I have an array like:
val=[[1,1,1,0,0,1,1,0,0,0], [0,1,1,1,0,1,1,0,0,0]]
I would like to access the indices where the value changes from 1 to 0.
Expected output is like:
[[(2,3),(4,5),(6,7)],[(0,1),(3,4),(4,5),(6,7)]]
I tried with np.gradient function, and able to find the gradient value. Instead of this is any better method:
X=np.gradient(val,axis=1)
Y=np.gradient(val,axis=0)
trans_YX = np.array(list(zip(Y.ravel(),X.ravel())),dtype('f4,f4')).reshape(Y.shape)
Current output:
[[(-1., 0. ) ( 0., 0. ) ( 0., -0.5) ( 1., -0.5) ( 0., 0.5) ( 0., 0.5)
( 0., -0.5) ( 0., -0.5) ( 0., 0. ) ( 0., 0. )]
[(-1., 1. ) ( 0., 0.5) ( 0., 0. ) ( 1., -0.5) ( 0., 0. ) ( 0., 0.5)
( 0., -0.5) ( 0., -0.5) ( 0., 0. ) ( 0., 0. )]]