Re: [Numpy-discussion] partial_sum/adj_difference?

2008-02-20 Thread Stefan van der Walt
On Tue, Feb 19, 2008 at 05:36:52PM -0700, Charles R Harris wrote:
 On Feb 19, 2008 2:20 PM, Stefan van der Walt [EMAIL PROTECTED] wrote:
 
 On Tue, Feb 19, 2008 at 01:50:04PM -0700, Charles R Harris wrote:
  And here I thought you were going to fix that. Deleting the
  blahs isn't a  fix, it's a coverup. Now there is no extended
  documentation at all.
 
 I wouldn't call Blah, blah extended documentation -- in fact, I
 would've been rather embarrassed if that showed up on my screen during
 a workshop.
 
 Blah, blah also doesn't strike me as the ideal TODO marker.  We can
 maybe use some more sensible text, or write a decorator to mark these
 functions.
 
 It has certainly been effective in practice.

Yes, ironically :)

http://projects.scipy.org/scipy/numpy/changeset/4813
http://projects.scipy.org/scipy/numpy/changeset/4814

The first courtesy of Matthew Brett.

Regards
Stéfan
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] partial_sum/adj_difference?

2008-02-19 Thread Neal Becker
Does numpy/scipy have a partial_sum and adj_difference function?

partial_sum[i] = \sum_{j=0}^{i} x[j]
adj_diff[i] = x[i] - x[i-1] : i  1, x[i] otherwise

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] partial_sum/adj_difference?

2008-02-19 Thread Francesc Altet
A Tuesday 19 February 2008, Neal Becker escrigué:
 Does numpy/scipy have a partial_sum and adj_difference function?

 partial_sum[i] = \sum_{j=0}^{i} x[j]
 adj_diff[i] = x[i] - x[i-1] : i  1, x[i] otherwise

I don't know, but by using views the next should be fairly efficient:

# Partial sum
In [28]: a = numpy.arange(10)
In [29]: ps = numpy.empty(len(a), 'int')
In [30]: for i in range(len(a)): ps[i] = a[:i].sum()
   :
In [31]: ps
Out[31]: array([ 0,  0,  1,  3,  6, 10, 15, 21, 28, 36])

# Adj difference:
In [35]: ad = numpy.empty(len(a), 'int')
In [36]: ad[0] = a[0]
In [37]: ad[1:] = a[1:] - a[:-1]
In [38]: ad
Out[38]: array([0, 1, 1, 1, 1, 1, 1, 1, 1, 1])

Cheers,

-- 
0,0   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 -
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] partial_sum/adj_difference?

2008-02-19 Thread Nadav Horesh



-Original Message-
From: [EMAIL PROTECTED] on behalf of Francesc Altet
Instead of

  for i in range(len(a)): ps[i] = a[:i].sum()

use

   a.cumsum()

  Nadav
Sent: Tue 19-Feb-08 20:59
To: Discussion of Numerical Python
Subject: Re: [Numpy-discussion] partial_sum/adj_difference?
 
A Tuesday 19 February 2008, Neal Becker escrigué:
 Does numpy/scipy have a partial_sum and adj_difference function?

 partial_sum[i] = \sum_{j=0}^{i} x[j]
 adj_diff[i] = x[i] - x[i-1] : i  1, x[i] otherwise

I don't know, but by using views the next should be fairly efficient:

# Partial sum
In [28]: a = numpy.arange(10)
In [29]: ps = numpy.empty(len(a), 'int')
In [30]: for i in range(len(a)): ps[i] = a[:i].sum()
   :
In [31]: ps
Out[31]: array([ 0,  0,  1,  3,  6, 10, 15, 21, 28, 36])

# Adj difference:
In [35]: ad = numpy.empty(len(a), 'int')
In [36]: ad[0] = a[0]
In [37]: ad[1:] = a[1:] - a[:-1]
In [38]: ad
Out[38]: array([0, 1, 1, 1, 1, 1, 1, 1, 1, 1])

Cheers,

-- 
0,0   Francesc Altet http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 -
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

winmail.dat___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] partial_sum/adj_difference?

2008-02-19 Thread Stefan van der Walt
Hi Neal

On Tue, Feb 19, 2008 at 01:38:06PM -0500, Neal Becker wrote:
 Does numpy/scipy have a partial_sum and adj_difference function?
 
 partial_sum[i] = \sum_{j=0}^{i} x[j]

numpy.cumsum

Yikes, the docstring contains Blah, blah.  I'll fix that
immediately.

 adj_diff[i] = x[i] - x[i-1] : i  1, x[i] otherwise

numpy.diff

Regards
Stéfan
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] partial_sum/adj_difference?

2008-02-19 Thread Pauli Virtanen
ti, 2008-02-19 kello 13:38 -0500, Neal Becker kirjoitti:
 Does numpy/scipy have a partial_sum and adj_difference function?
 
 partial_sum[i] = \sum_{j=0}^{i} x[j]
 adj_diff[i] = x[i] - x[i-1] : i  1, x[i] otherwise

cumsum and diff do something like this:

 import numpy
 a = [1,2,3,4,5,3,1]
 numpy.cumsum(a)
array([ 1,  3,  6, 10, 15, 18, 19])
 numpy.diff(a)
array([ 1,  1,  1,  1, -2, -2])



signature.asc
Description: Digitaalisesti allekirjoitettu viestin osa
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] partial_sum/adj_difference?

2008-02-19 Thread Pierre GM
 On Feb 19, 2008 11:38 AM, Neal Becker [EMAIL PROTECTED] wrote:

  adj_diff[i] = x[i] - x[i-1] : i  1, x[i] otherwise

 Well, x[1:] - x[:-1] will give the usual differences. If you need the
 leading x[0] prefix the x vector with a 0.

There's also numpy.diff, and the little known numpy.ediff1d
x=numpy.arange(10)
numpy.ediff1d(x,to_begin=0)
array([0, 1, 1, 1, 1, 1, 1, 1, 1, 1])
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] partial_sum/adj_difference?

2008-02-19 Thread Charles R Harris
On Feb 19, 2008 12:41 PM, Stefan van der Walt [EMAIL PROTECTED] wrote:

 Hi Neal

 On Tue, Feb 19, 2008 at 01:38:06PM -0500, Neal Becker wrote:
  Does numpy/scipy have a partial_sum and adj_difference function?
 
  partial_sum[i] = \sum_{j=0}^{i} x[j]

 numpy.cumsum

 Yikes, the docstring contains Blah, blah.  I'll fix that
 immediately.


Gosh,

And here I thought you were going to fix that. Deleting the blahs isn't a
fix, it's a coverup. Now there is no extended documentation at all.

Chuck
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] partial_sum/adj_difference?

2008-02-19 Thread Nils Wagner
On Tue, 19 Feb 2008 13:50:04 -0700
  Charles R Harris [EMAIL PROTECTED] wrote:
 On Feb 19, 2008 12:41 PM, Stefan van der Walt 
[EMAIL PROTECTED] wrote:
 
 Hi Neal

 On Tue, Feb 19, 2008 at 01:38:06PM -0500, Neal Becker 
wrote:
  Does numpy/scipy have a partial_sum and adj_difference 
function?
 
  partial_sum[i] = \sum_{j=0}^{i} x[j]

 numpy.cumsum

 Yikes, the docstring contains Blah, blah.  I'll fix 
that
 immediately.

 
 Gosh,
 
 And here I thought you were going to fix that. Deleting 
the blahs isn't a
 fix, it's a coverup. Now there is no extended 
documentation at all.
 
 Chuck

;-)

 from numpy import cumprod
 help (cumprod)

Nils
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] partial_sum/adj_difference?

2008-02-19 Thread Stefan van der Walt
On Tue, Feb 19, 2008 at 01:50:04PM -0700, Charles R Harris wrote:
 And here I thought you were going to fix that. Deleting the blahs isn't a
 fix, it's a coverup. Now there is no extended documentation at all.

I wouldn't call Blah, blah extended documentation -- in fact, I
would've been rather embarrassed if that showed up on my screen during
a workshop.

Blah, blah also doesn't strike me as the ideal TODO marker.  We can
maybe use some more sensible text, or write a decorator to mark these
functions.

I'd say we add them to the TODO list for the next doc-day and run with
it...

Regards
Stéfan
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] partial_sum/adj_difference?

2008-02-19 Thread Charles R Harris
On Feb 19, 2008 2:20 PM, Stefan van der Walt [EMAIL PROTECTED] wrote:

 On Tue, Feb 19, 2008 at 01:50:04PM -0700, Charles R Harris wrote:
  And here I thought you were going to fix that. Deleting the blahs
 isn't a
  fix, it's a coverup. Now there is no extended documentation at all.

 I wouldn't call Blah, blah extended documentation -- in fact, I
 would've been rather embarrassed if that showed up on my screen during
 a workshop.

 Blah, blah also doesn't strike me as the ideal TODO marker.  We can
 maybe use some more sensible text, or write a decorator to mark these
 functions.


It has certainly been effective in practice.

Chuck
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion