Hi Bruce,
In the context of the actual problem, I have a long series of
non-equidistant and irregularly spaced float numbers and I have to take
values between given limits with the constraint of keeping a minimal
separation. Option 2 just misses the first value of the input array if
it is with
On 06/09/2010 10:24 AM, Vicente Sole wrote:
? Well a loop or list comparison seems like a good choice to me. It is
much more obvious at the expense of two LOCs. Did you profile the two
possibilities and are they actually performance-critical?
cheers
The second is between 8 and ten tim
Hi Josef,
I do not need regular spacing of the original data. I only need them to
be sorted and that I get it with a previous numpy call. Then the
algorithm using the cumsum does the trick without a explicit loop.
Armando
___
NumPy-Discussion mailin
On Wed, Jun 9, 2010 at 11:47 AM, Vicente Sole wrote:
> Quoting josef.p...@gmail.com:
>
>> but the two options don't produce the same result in general, the
>> cumsum version doesn't restart from zero, I think
>>
>> try
>> x0 = np.random.randint(5,size=30).cumsum()
>> with delta=3
>>
>> I don't see
Quoting josef.p...@gmail.com:
> but the two options don't produce the same result in general, the
> cumsum version doesn't restart from zero, I think
>
> try
> x0 = np.random.randint(5,size=30).cumsum()
> with delta=3
>
> I don't see a way around recursive looping
>
The x0 data are already sorted
On Wed, Jun 9, 2010 at 11:31 AM, Vicente Sole wrote:
> It gets even worse with data similar to those I will be using.
>
> With:
>
> x0 = numpy.linspace(-1,1, 1)
> niter = 2000
>
> I get 24 seconds for option1 and 0.64 seconds for option2.
> Considering I expect between 5 and 50 times that numb
It gets even worse with data similar to those I will be using.
With:
x0 = numpy.linspace(-1,1, 1)
niter = 2000
I get 24 seconds for option1 and 0.64 seconds for option2.
Considering I expect between 5 and 50 times that number of iterations,
the difference is already quite considerable.
Ar
>> ? Well a loop or list comparison seems like a good choice to me. It is
>> much more obvious at the expense of two LOCs. Did you profile the two
>> possibilities and are they actually performance-critical?
>>
>> cheers
>>
The second is between 8 and ten times faster on my machine.
import numpy
Correct. I thought just multiplying by -1 and inverting the logical
condition would give me the same output.
This makes exactly what I want:
>>> x= numpy.arange(10.)
>>> delta=3
>>> y=[x[0]]
>>> for value in x:
> ... if (value-y[-1]) < delta:
> ...y.append(value)
> ...
>>> y
[0., 4.
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)
/
>/ Given a certain value delta, I would like to get a subset of x, named
/>/ y,
/>/ where (y[i+1] - y[i])>= delta
/
So in fact the problem is to find y such that
(y[i(k)+n] - y[i(k)])>= delta
for n<= len(x) - 1 - i
and i(0) = 0, i(k+1) = i(k) + n
? Well a loop or list comparison seems like
Well happens. The problem description was not 100% clear thus I still
think your line did solve the problem. A simple misunderstanding. So
what do I learn from it?: Always look at the code, not the
description :D
Am Mittwoch, den 09.06.2010, 10:19 +0200 schrieb Francesc Alted:
> A Wednesday 09 Jun
> Given a certain value delta, I would like to get a subset of x, named
> y,
> where (y[i+1] - y[i]) >= delta
So in fact the problem is to find y such that
(y[i(k)+n] - y[i(k)]) >= delta
for n <= len(x) - 1 - i
and i(0) = 0, i(k+1) = i(k) + n
? Well a loop or list comparison seems like a good
A Wednesday 09 June 2010 10:14:22 V. Armando Solé escrigué:
> 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
Francesc Alted wrote:
> Yeah, damn you! ;-)
>
I think you still have room for improvement ;-)
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Yeah, damn you! ;-)
A Wednesday 09 June 2010 10:11:33 Robert Elsner escrigué:
> Hah beat you to it one minute ;)
>
> Am Mittwoch, den 09.06.2010, 10:08 +0200 schrieb Francesc Alted:
> > A Wednesday 09 June 2010 10:00:50 V. Armando Solé escrigué:
> > > Well, this seems to be quite close to what I
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
Hah beat you to it one minute ;)
Am Mittwoch, den 09.06.2010, 10:08 +0200 schrieb Francesc Alted:
> 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.non
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
There might be an easier way to accomplish that
y = x[(x[1:]-x[:-1]) >= delta]
cheers
Am Mittwoch, den 09.06.2010, 10:00 +0200 schrieb "V. Armando Solé":
> 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:]
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 bec
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 op
22 matches
Mail list logo