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

Robert Elsner mlist at re-factory.de
Wed Jun 9 11:07:33 EDT 2010


I suspect the author meant that instead (or a simple minus in front of
the delta). Just posting because I wondered the same this morning after
looking at it (after the first misunderstanding).
It looks much better to me than the cumsum approach with its hidden test
for true using .astype(numpy.int)


x= numpy.arange(10.)
delta=3
y=[x[0]]
for value in x:
    if (value - y[-1]) > delta:
        y.append(value)
        
        
print y


Am Mittwoch, den 09.06.2010, 09:24 -0500 schrieb Bruce Southey:
> 
> Playing around with range/arange can be misleading as
> >> x[x%4==0]
> array([ 0.,  4.,  8.])
> 
> I don't know you really want because your first code 
> >>> x= numpy.arange(10.)
> >>> delta=3
> >>> y=[x[0]]
> >>> for value in x:
> ...     if (y[-1] -value) < delta:
> ...        y.append(value)
> ... 
> >>> y
> [0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
> 
> Which is not [0, 4, 8].
> 
> Bruce 





More information about the NumPy-Discussion mailing list