[Numpy-discussion] Simple problem. Is it possible without a loop?
Wed Jun 9 10:58:29 CDT 2010
On Wed, Jun 9, 2010 at 11:47 AM, Vicente Sole <email@example.com> wrote:
> Quoting firstname.lastname@example.org:
>> but the two options don't produce the same result in general, the
>> cumsum version doesn't restart from zero, I think
>> 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]]
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
> NumPy-Discussion mailing list
More information about the NumPy-Discussion