I have a large ndarray X
(roughly (1e3, 1e3, 1e3)), where I want to do manipulations of X
including and not including particular elements of the 0th axis (for each element of the 1st and 2nd axes). i.e. there are (1e3, 1e3) elements which I want to (at times) mask in or out.
The simplest thing to do would be to construct a masked array like,
Z = np.zeros_like(X, dtype=bool)
# assume `inds` is some indexing array which will target
# the particular (1e3 x 1e3) elements I'm interested in
Z[inds] = True
Y = np.ma.masked_array(X, mask=Z)
But this uses an extra gigabyte of memory just for the masking array.
Is there any way to do this without constructing a second 10^9
element array of masks? For example, is it possible to construct a sparse-matrix for the mask?