Excerpts from Xavier Barthelemy's message of mar. déc. 06 06:53:09 +0100 2011: > Hi everyone > > I was wondering if there is a more optimal way to write what follows: > I am studying waves, so I have an array of wave crests positions, Xcrest > and the positions of the ZeroCrossings, Xzeros. > > The goal is to find between which Xzeros my xcrest are. > > > XXX1=XCrest > CrestZerosNeighbour=np.zeros([len(XCrest),2], dtype='d') > for nn in range(len(Xzeros)-1): > X1=Xzeros[nn] > X2=Xzeros[nn+1] > indexxx1=np.where((X1<=XXX1) & (XXX1 < X2)) > try: > CrestZerosNeighbour[indexxx1[0]]=np.array([X1,X2]) > except: > pass > > Someone has an idea? in the spirit of (numpy.ma.masked_outside) which does > exactly the opposite I want: it masks an array outside an interval. I would > like to mask everything except the interval that contains my value. > I do this operation a large number of times , and a loop is time consuming.
Hi, My first idea would be to write a function in C or Fortran that return Xzeros index (instead of values). Algorithms may be optimized according to the inputs: if the XCrest are Xzeros sorted, if len(Xcreast) >> len(Xzeros) using dichotomy... But I would be interested to see a solution with masked array too. -- _______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
