我有這個 5x5 眼睛陣列,我應該使用 'trace' 關鍵字從 k=1 計算總和,但結果我必須更改跟蹤開始位置,我該怎么做?
import numpy as np
# TODO: Trace an eye
eye_0 = np.eye(5,5, k=1)
trace_eye = np.trace(eye_0)
print(eye_0)
trace_eye
[[0. 1. 0. 0. 0.]
[0. 0. 1. 0. 0.]
[0. 0. 0. 1. 0.]
[0. 0. 0. 0. 1.]
[0. 0. 0. 0. 0.]]
0.0
uj5u.com熱心網友回復:
Numpy.trace 有一個偏移引數:
np.trace(eye_0, offset = 1)
在您的情況下,這將回傳 4。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/391876.html
