I have a 3D array, say a
. I want to create another array b
which has 0
s at least and second least absolute values in a
. My approach is as follows
<code>import numpy as np
a = np.random.randn(100, 4, 4)
c = np.argsort(np.abs(a), axis=2)[..., :2]
b = np.ones(a.shape)
# I need to do b[c] = 0
</code>
<code>import numpy as np
a = np.random.randn(100, 4, 4)
c = np.argsort(np.abs(a), axis=2)[..., :2]
b = np.ones(a.shape)
# I need to do b[c] = 0
</code>
import numpy as np
a = np.random.randn(100, 4, 4)
c = np.argsort(np.abs(a), axis=2)[..., :2]
b = np.ones(a.shape)
# I need to do b[c] = 0
However the code b[c] = 0
does not work. Also c
has entries from 0
to 3
only, therefore the indices for first and second dimension in b
need to be inferred from the location of the index in c
. How does one go about it? Any help is appreciated.