Looping through each item in a numpy array?

前端 未结 3 722
梦如初夏
梦如初夏 2021-01-27 09:08

I\'m trying to access each item in a numpy 2D array.

I\'m used to something like this in Python [[...], [...], [...]]

for row in data:
    for col in dat         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-27 09:28

    Try np.ndenumerate:

    >>> a =numpy.array([[1,2],[3,4]])
    >>> for (i,j), value in np.ndenumerate(a):
    ...  print(i, j, value)
    ... 
    0 0 1
    0 1 2 
    1 0 3
    1 1 4
    

提交回复
热议问题