Re: [Numpy-discussion] calculating the difference of an array

2010-01-02 Thread Manuel Wittchen
Hi, Thanks for your help. I tried np.diff() before, but the result looked like this: RESULT = [1, 1, 1, 1] So I was thinking that np.diff() doesn't iterate over the values of the array. So I gave the for-loop a try. Now, seeing your code below, I realized that my mistake was that I used ARRAY =

Re: [Numpy-discussion] calculating the difference of an array

2010-01-02 Thread Emmanuelle Gouillart
Hello Manuel, the discrete difference of a numpy array can be written in a very natural way, without loops. Below are two possible ways to do it: >>> a = np.arange(10)**2 >>> a array([ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81]) >>> a[1:] - a[:-1] array([ 1, 3, 5, 7, 9, 11, 13, 15, 17]) >>> np.di

Re: [Numpy-discussion] calculating the difference of an array

2010-01-02 Thread David Cournapeau
On Sat, Jan 2, 2010 at 7:23 PM, Manuel Wittchen wrote: > Hi, > > I want to calculate the difference between the values of a > numpy-array. The formula is: > > deltaT = t_(n+1) - t_(n) > > My approach to calculate the difference looks like this: > > for i in len(ARRAY): >        delta_t[i] = ARRAY[

[Numpy-discussion] calculating the difference of an array

2010-01-02 Thread Manuel Wittchen
Hi, I want to calculate the difference between the values of a numpy-array. The formula is: deltaT = t_(n+1) - t_(n) My approach to calculate the difference looks like this: for i in len(ARRAY): delta_t[i] = ARRAY[(i+1):] - ARRAY[:(len(ARRAY)-1)] print "result:", delta_t But I get a T