Hi, Currently I have a code that checks if given element in array is equal = 0 and if so then set the value to 'level' value (temp_board is 2D numpy array, indices_to_watch contains 2D coordinates that should be watched for zeros).
indices_to_watch = [(0,1), (1,2)]
for index in indices_to_watch:
if temp_board[index] == 0:
temp_board[index] = level
I would like to convert this to a more numpy-like approach (remove the for and use only numpy functions) to speed this up. Here's what I tried:
masked = np.ma.array(temp_board, mask=(a!=0), hard_mask=True)
masked.put(indices_to_watch, level)
But unfortunately masked array when doing put() wants to have 1D dimensions (totally strange!), is there some other way of updating array elements that are equal to 0 and have concrete indices?
Or maybe using masked arrays is not the way to go?