[Numpy-discussion] Simple problem. Is it possible without a loop?
"V. Armando Solé"
sole@esrf...
Wed Jun 9 03:00:50 CDT 2010
Well, this seems to be quite close to what I need
y = numpy.cumsum((x[1:]-x[:-1])/delta).astype(numpy.int)
i1 = numpy.nonzero(y[1:] > y[:-1])
y = numpy.take(x, i1)
Sorry for the time taken!
Best regards,
Armando
V. Armando Solé wrote:
> 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
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
More information about the NumPy-Discussion
mailing list