Assume an array of
0 = {ndarray: (4,)} [5 0 3 3]
1 = {ndarray: (4,)} [7 9 3 5]
2 = {ndarray: (4,)} [2 4 7 6]
3 = {ndarray: (4,)} [8 8 1 6]
I would like slice index where epoch_label is equal to zero
[1 1 0 0]
From above, the index will be the second and third index
- Remarks:
epoch_labelis an integer, and the value can be 0,1,2,...
Using masked_where, this will produce something as
[1 1 -- --]
And, the expected output should be
[2 4 7 6]
[8 8 1 6]
However, using the code below
epoch_com = [np.random.randint(10, size=4) for _ in range(Nepochs)]
epoch_com_arr=np.array(epoch_com)
epoch_label=np.random.randint(2, size=Nepochs)
mm=ma.masked_where(epoch_label == 0, epoch_label)
expected_output=np.where(epoch_com_arr[mm,:])
The above snippet code produce
0 = {ndarray: (14,)} [0 0 0 0 1 1 1 1 2 2 2 3 3 3]
1 = {ndarray: (14,)} [0 1 2 3 0 1 2 3 0 2 3 0 2 3]
which is not as per I intend
or
expected_output=epoch_com_arr[mm,:]
which produced
0 = {ndarray: (4,)} [7 9 3 5]
1 = {ndarray: (4,)} [7 9 3 5]
2 = {ndarray: (4,)} [5 0 3 3]
3 = {ndarray: (4,)} [5 0 3 3]
May I know how to solve this