采用
zip
indices = zip(*np.where(myarray == 0))
那你可以做
for i, j, k in indices: print ...
例如,
In [1]: x = np.random_integers(0, 1, (3, 3, 3))In [2]: np.where(x) # you want np.where(x==0)Out[2]: (array([0, 0, 0, 0, 0, 1, 1, 1, 1, 2]), array([0, 1, 1, 2, 2, 0, 0, 1, 1, 2]), array([1, 0, 1, 0, 1, 1, 2, 0, 2, 2]))In [3]: zip(*np.where(x))Out[3]: [(0, 0, 1), (0, 1, 0), (0, 1, 1), (0, 2, 0), (0, 2, 1), (1, 0, 1), (1, 0, 2), (1, 1, 0), (1, 1, 2), (2, 2, 2)]



