2017-11-23T09:15:30Z||2017-11-23T09:15:30Z


创建一个3x4的二维数组,枚举索引的时候,去掉(1,1)和(1,2),代码:

import numpy as np

values = np.zeros((3, 4))

ignore = set([(1,1), (1,2)])
valid = [index for index in np.ndenumerate(values) if not index in ignore]

for (x, y), value in valid:
  print(x, y, value)

输出:

(0, 0, 0.0)
(0, 1, 0.0)
(0, 2, 0.0)
(0, 3, 1.0)
(1, 0, 0.0)
(1, 1, 0.0)
(1, 2, 0.0)
(1, 3, -1.0)
(2, 0, 0.0)
(2, 1, 0.0)
(2, 2, 0.0)
(2, 3, 0.0)