[Numpy-discussion] Simple problem. Is it possible without a loop?
josef.pktd@gmai...
josef.pktd@gmai...
Wed Jun 9 10:58:29 CDT 2010
On Wed, Jun 9, 2010 at 11:47 AM, Vicente Sole <sole@esrf.fr> wrote:
> Quoting josef.pktd@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. It was one of the premises of the first post.
>
> The solution I proposed makes "almost" what I need and I will most
> likely use it. It just misses the first value but takes the next one
> what is fine for my application. For the simple example, it returns
> [1, 5, 9] instead of [0, 4, 8] but it should not disturb me.
but unless you have pretty regular spacing, np.diff(y) can be anything
e.g. in a random example, increments of y are
if x0 is weakly increasing
[[5 0 3 3 4 9 6 0 6 1 8 4]]
and
if x0 is strictly increasing
[[ 2 4 7 1 9 9 5 4 6 2 5 11]]
maybe you should check np.diff(y) for your case, in my random example
>>> (np.diff(y1)<delta).mean()
0.0
>>> (np.diff(y2)<delta).mean()
0.25
Josef
>
> 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