[Numpy-discussion] Simple problem. Is it possible without a loop?
"V. Armando Solé"
sole@esrf...
Wed Jun 9 03:14:22 CDT 2010
That was my first thought, but that only warrants me to skip one point
in x but not more than one.
>>> x= numpy.arange(10.)
>>> delta = 3
>>> print x[(x[1:] - x[:-1]) >= delta]
[]
instead of the requested [0, 4, 8]
Armando
Francesc Alted wrote:
> A Wednesday 09 June 2010 10:00:50 V. Armando Solé escrigué:
>
>> 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)
>>
>
> Perhaps this is a bit shorter:
>
> y = x[(x[1:] - x[:-1]) >= delta]
>
>
More information about the NumPy-Discussion
mailing list