[英]How can iterate over a 2-D matrix in python with respect to coloumns and rows?
你可以初始化一個數組
rows = 2
cols = 5
a = np.zeros((rows, cols), float)
這將打印為:
array([[ 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0.]])
然后您可以按如下方式訪問您的元素:
row_index = 1
col_index = 3
a[row_index, col_index] = 5
結果 a 是:
array([[ 0., 0., 0., 0., 0.],
[ 0., 0., 0., 5., 0.]])
正如您在 python 中看到的, row_index 從0 .. rows-1
。
它認為有了這些知識,您應該能夠實施您的公式。
讓我們知道它的進展情況以及您需要更多幫助的地方。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.