I have a huge 3d NumPy array and a same shaped mask array filled with ones or zeros. Let's use this as an example:
arr = np.random.randint(1, 100, size=(4, 4, 4))
mask = np.zeros(shape=(4,4,4), dtype='int')
mask[0,2:3,:] = 1
My goal is to get a same shaped array (in this example (4,4,4)), let's name it new_arr, with the values from arr where mask == 1. All other values in new_arr should get be -2. (not 0)
However, doing this:
new_arr = arr[mask]
results in a (4, 4, 4, 4, 4) shaped array.
So, I've got pretty much 2 question: 1:) How do I get my desired result and 2.) Why does masking a 3d NumPy array this way result in a 5d array.