python-如何遍历数组所有元素并获取其索引

import numpy as npa = np.array([[1, 2], [3, 4]]) # 遍历数组并返回索引及其对应的元素 for index, element in np.ndenumerate(a): print(index, element) # (0, 0) 1 # (0, 1) 2 # (1, 0) 3 # (1, 1) 4

    推荐阅读