I am trying to set certain values of an array to 0. I have a larger array with many different values but want to set a random square/rectangle subset of values to zero.
a = np.array([[[1,1,1],[2,2,2],[3,3,3]],[[4,4,4],[5,5,5],[6,6,6]],[[7,7,7],[8,8,8],[9,9,9]]])
b = np.zeros((2,2,3))
#combination function
Expected Result:
combination =
array([[[1, 1, 1],
[2, 2, 2],
[3, 3, 3]],
[[4, 4, 4],
[0, 0, 0],
[0, 0, 0]],
[[7, 7, 7],
[0, 0, 0],
[0, 0, 0]]])
I know this is wrong but, I tried just multiplying them like this but got an error:
masked = a*b
ValueError: operands could not be broadcast together with shapes (3,3,3) (2,2,3)
a[0, np.arange(3)] = 0