Numpy tips

lun. 04 octobre 2010 by Martin Deudon
np.where(np.diff(np.sign(x)))[0]

Find points of x crossing the threshold T :

np.where(np.diff(x > T))[0] 

Find points of x crossing threshold ascending :

np.where(np.diff(x > T) & (x[1:] > T))

Remove points that are close, i.e. given a sorted array : $$ if\ (x_i - x_{i-1}) < M\ then\ remove\ x_i\ $$

x[np.hstack([True, np.diff(x) > M])]