What I have:
import numpy as np
np.random.seed(42)
dlen = 250000
data = np.random.rand(dlen, 3, 3)
mask = np.random.choice([0, 1, 2], dlen)
What I want to get:
[[0.37454012 0.95071431 0.73199394],
[0.83244264 0.21233911 0.18182497],
[0.13949386 0.29214465 0.36636184],
[0.94888554 0.96563203 0.80839735],
[0.44015249 0.12203823 0.49517691],
....
(250000, 3)
What I try to use for this:
data[:,mask,:]
{MemoryError}Unable to allocate 1.36 TiB for an array with shape (250000, 250000, 3) and data type float64
What gives the correct result but looks strange:
data[np.arange(data.shape[0]), mask, :]
So what's the correct way to use this mask?
Upd.: The mask should select the column with the specified index. Example for an array with shape [2,3,3]:
array = [[[5 6 7], [7 8 9], [2 3 4]],
[[2 1 0], [7 6 5], [7 6 5]]]
mask = [1 0]
result = [[7 8 9],
[2 1 0]]
..gives the correct result but looks strange- That works because your are using an Index array