I have a 3D numpy.MaskedArray
and I want to delete the 3rd slice. If I was a numpy.array I could just use the numpy.delete
function, e.g. np.delete(arr, obj=3, axis=0)
. However, this function is not available for np.MaskedArrays
. How can I do this in a pythonic way and without changing the array type?
Asked
Active
Viewed 46 times
0

pan
- 101
- 4
-
There's nothing especially 'pythonic' about `np.delete`, other than the fact that it is a `numpy` function. Under the covers it is just Python code, rather complex because it tries to be general purpose. – hpaulj Nov 06 '19 at 15:52
1 Answers
1
My memory of np.delete
code is that in your case it would do:
np.ma.vstack([ arr[:3], arr[4:])

hpaulj
- 221,503
- 14
- 230
- 353