[Numpy-discussion] Simple problem. Is it possible without a loop?

"V. Armando Solé" sole@esrf...
Wed Jun 9 02:45:12 CDT 2010


Hello,

I am trying to solve a simple problem that becomes complex if I try to 
avoid looping.

Let's say I have a 1D array, x,  where x[i] <= x[i+1]

Given a certain value delta, I would like to get a subset of x, named y, 
where (y[i+1] - y[i]) >= delta

In a non-optimized and trivial way, the operation I would like to do is:

y=[x[0]]
for value in x:
    if (y[-1] -value) < delta:
       y.append(value)
y=numpy.array(y)

Any hint?

Best regards,

Armando



More information about the NumPy-Discussion mailing list