目前我有一个代码检查数组中的给定元素是否等于0,如果是,则将值设置为'level'值(temp_board是2D numpy数组,indices_to_watch包含应该观察的2D坐标为零)。Numpy masked array modification
indices_to_watch = [(0,1), (1,2)]
for index in indices_to_watch:
if temp_board[index] == 0:
temp_board[index] = level
我想这个转换为更numpy的类似方法(去掉了,并且只使用numpy的功能),以加快这。 这里是我的尝试:
masked = np.ma.array(temp_board, mask=(a!=0), hard_mask=True)
masked.put(indices_to_watch, level)
但不幸的是掩盖阵列在做把()希望有一维的尺寸(完全陌生的!),有没有更新是等于0,并有具体的数组元素的一些其他的方式指数?
或者,也许使用屏蔽阵列是不是要走的路?
谢谢:) 我试过numpy.where()但没想到将它与set set intersection – 2010-02-23 12:27:41