Let's say I have a numpy.ndarray
:
a = np.array([0,4,10,0,11,10])
I compared this with 10.
a >= 10
# array([False, False, True, False, True, True], dtype=bool)
I would like to have a single True, i.e. True only at the first occurrence.
I would like to apply this to a given axis in n-D numpy.ndarray.(say, 1000*1000*10)
a_2d = np.array([[0,4,10],[0,11,10]])
#if axis == 1: array([[False, False, True], [False, True, False]])
What I have done:
As for a 1-D array, I managed to do it by using this.
b=np.zeros(a.size)
b[np.argmax(a>=10)]=True
#b=array([ 0., 0., 1., 0., 0., 0.])
However, I have no idea how to apply this to a large n-D array.