Iterate over numpy with index (numpy equivalent of python enumerate)

后端 未结 3 1167
甜味超标
甜味超标 2020-12-20 19:11

I\'m trying to create a function that will calculate the lattice distance (number of horizontal and vertical steps) between elements in a multi-dimensional numpy array. For

3条回答
  •  长情又很酷
    2020-12-20 20:01

    You can iterate through the values in your array with numpy.ndenumerate to get the indices of the values in your array.

    Using the documentation above:

    A = np.array([[1,2,3],[4,5,6],[7,8,9]])
    for index, values in np.ndenumerate(A):
        print(index, values)  # operate here
    

提交回复
热议问题