There is a 1D array of values:
arr0 = numpy.array([8,0,9,5])
There is another 2D array whose shape is (len(arr0),3)
:
arr1 = numpy.array([9,5,6],
[2,7,4],
[6,7,8],
[1,8,3])
I want to create a masked array of arr1
where arr1[i]
is masked if arr0[i] == 0
:
Result arr2 = [[9,5,6],
[-,-,-],
[6,7,8],
[1,8,3]]
What is an elegant way to create this new masked array?
I know I can create it using a mask of shape (len(arr0),3)
. I am hoping I can create this using a mask of shape that is just (len(arr0))
.