[Numpy-discussion] categorical distributions

2010-11-21 Thread Hagen Fürstenau
Hi, numpy doesn't seem to have a function for sampling from simple categorical distributions. The easiest solution I could come up with was something like >>> from numpy.random import multinomial >>> multinomial(1, [.5, .3, .2]).nonzero()[0][0] 1 but this is bound to be inefficient as soon as th

Re: [Numpy-discussion] Slow element-by-element access?

2010-11-21 Thread Charles R Harris
On Sun, Nov 21, 2010 at 11:17 PM, Bruce Sherwood wrote: > A colleague showed me a program using Numeric with Python 2.5 which > ran much faster than the same program using numpy with Python 2.7. I > distilled this down to a simple test case, characterized by a "for" > loop in which he does an ele

[Numpy-discussion] Slow element-by-element access?

2010-11-21 Thread Bruce Sherwood
A colleague showed me a program using Numeric with Python 2.5 which ran much faster than the same program using numpy with Python 2.7. I distilled this down to a simple test case, characterized by a "for" loop in which he does an element-by-element calculation involving arrays: from numpy import a

Re: [Numpy-discussion] Does np.std() make two passes through the data?

2010-11-21 Thread Keith Goodman
On Sun, Nov 21, 2010 at 5:56 PM, Robert Kern wrote: > On Sun, Nov 21, 2010 at 19:49, Keith Goodman wrote: > >> But this sample gives a difference: >> a = np.random.rand(100) a.var() >>   0.080232196646619805 var(a) >>   0.080232196646619791 >> >> As you know, I'm trying to make a d

Re: [Numpy-discussion] [ANN] Nanny, faster NaN functions

2010-11-21 Thread Wes McKinney
On Sun, Nov 21, 2010 at 6:37 PM, Keith Goodman wrote: > On Sun, Nov 21, 2010 at 3:16 PM, Wes McKinney wrote: > >> What would you say to a single package that contains: >> >> - NaN-aware NumPy and SciPy functions (nanmean, nanmin, etc.) > > I'd say yes. > >> - moving window functions (moving_{coun

Re: [Numpy-discussion] Does np.std() make two passes through the data?

2010-11-21 Thread Robert Kern
On Sun, Nov 21, 2010 at 19:49, Keith Goodman wrote: > But this sample gives a difference: > >>> a = np.random.rand(100) >>> a.var() >   0.080232196646619805 >>> var(a) >   0.080232196646619791 > > As you know, I'm trying to make a drop-in replacement for > scipy.stats.nanstd. Maybe I'll have to a

Re: [Numpy-discussion] Does np.std() make two passes through the data?

2010-11-21 Thread Keith Goodman
On Sun, Nov 21, 2010 at 4:18 PM, wrote: > On Sun, Nov 21, 2010 at 6:43 PM, Keith Goodman wrote: >> Does np.std() make two passes through the data? >> >> Numpy: >> arr = np.random.rand(10) arr.std() >>   0.3008736260967052 >> >> Looks like an algorithm that makes one pass through the da

Re: [Numpy-discussion] Does np.std() make two passes through the data?

2010-11-21 Thread Robert Kern
On Sun, Nov 21, 2010 at 17:43, Keith Goodman wrote: > Does np.std() make two passes through the data? Yes. See PyArray_Std() in numpy/core/src/calculation.c -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt

Re: [Numpy-discussion] Does np.std() make two passes through the data?

2010-11-21 Thread josef . pktd
On Sun, Nov 21, 2010 at 6:43 PM, Keith Goodman wrote: > Does np.std() make two passes through the data? > > Numpy: > >>> arr = np.random.rand(10) >>> arr.std() >   0.3008736260967052 > > Looks like an algorithm that makes one pass through the data (one for > loop) wouldn't match arr.std(): > >>> n

[Numpy-discussion] Does np.std() make two passes through the data?

2010-11-21 Thread Keith Goodman
Does np.std() make two passes through the data? Numpy: >> arr = np.random.rand(10) >> arr.std() 0.3008736260967052 Looks like an algorithm that makes one pass through the data (one for loop) wouldn't match arr.std(): >> np.sqrt((arr*arr).mean() - arr.mean()**2) 0.30087362609670526 But a

Re: [Numpy-discussion] [ANN] Nanny, faster NaN functions

2010-11-21 Thread Keith Goodman
On Sun, Nov 21, 2010 at 3:16 PM, Wes McKinney wrote: > What would you say to a single package that contains: > > - NaN-aware NumPy and SciPy functions (nanmean, nanmin, etc.) I'd say yes. > - moving window functions (moving_{count, sum, mean, var, std, etc.}) Yes. BTW, we both do arr=arr.asty

Re: [Numpy-discussion] [ANN] Nanny, faster NaN functions

2010-11-21 Thread Wes McKinney
On Sun, Nov 21, 2010 at 6:02 PM, wrote: > On Sun, Nov 21, 2010 at 5:09 PM, Keith Goodman wrote: >> On Sun, Nov 21, 2010 at 12:30 PM,   wrote: >>> On Sun, Nov 21, 2010 at 2:48 PM, Keith Goodman wrote: On Sun, Nov 21, 2010 at 10:25 AM, Wes McKinney wrote: > On Sat, Nov 20, 2010 at 7:24

Re: [Numpy-discussion] [ANN] Nanny, faster NaN functions

2010-11-21 Thread josef . pktd
On Sun, Nov 21, 2010 at 5:09 PM, Keith Goodman wrote: > On Sun, Nov 21, 2010 at 12:30 PM,   wrote: >> On Sun, Nov 21, 2010 at 2:48 PM, Keith Goodman wrote: >>> On Sun, Nov 21, 2010 at 10:25 AM, Wes McKinney wrote: On Sat, Nov 20, 2010 at 7:24 PM, Keith Goodman wrote: > On Sat, Nov 20,

Re: [Numpy-discussion] [ANN] Nanny, faster NaN functions

2010-11-21 Thread Keith Goodman
On Sun, Nov 21, 2010 at 12:30 PM, wrote: > On Sun, Nov 21, 2010 at 2:48 PM, Keith Goodman wrote: >> On Sun, Nov 21, 2010 at 10:25 AM, Wes McKinney wrote: >>> On Sat, Nov 20, 2010 at 7:24 PM, Keith Goodman wrote: On Sat, Nov 20, 2010 at 3:54 PM, Wes McKinney wrote: > Keith (and o

Re: [Numpy-discussion] indexing question

2010-11-21 Thread Ernest Adrogué
Hi, 21/11/10 @ 11:28 (-0800), thus spake John Salvatier: > yes use the symbol ':' > > so you want > > t[:,x,y] I tried that, but it's not the same: In [307]: t[[0,1],x,y] Out[307]: array([1, 7]) In [308]: t[:,x,y] Out[308]: array([[1, 3], [5, 7]]) No? -- Ernest

Re: [Numpy-discussion] [ANN] Nanny, faster NaN functions

2010-11-21 Thread Wes McKinney
On Sat, Nov 20, 2010 at 7:24 PM, Keith Goodman wrote: > On Sat, Nov 20, 2010 at 3:54 PM, Wes McKinney wrote: > >> Keith (and others), >> >> What would you think about creating a library of mostly Cython-based >> "domain specific functions"? So stuff like rolling statistical >> moments, nan* funct

Re: [Numpy-discussion] Where did the github numpy repository go?

2010-11-21 Thread Friedrich Romstedt
2010/11/14 Charles R Harris : > I keep getting page does not exist. The comments on the event, https://github.com/blog/744-today-s-outage, are simply great and stunning. Friedrich ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.

Re: [Numpy-discussion] [ANN] Nanny, faster NaN functions

2010-11-21 Thread josef . pktd
On Sun, Nov 21, 2010 at 2:48 PM, Keith Goodman wrote: > On Sun, Nov 21, 2010 at 10:25 AM, Wes McKinney wrote: >> On Sat, Nov 20, 2010 at 7:24 PM, Keith Goodman wrote: >>> On Sat, Nov 20, 2010 at 3:54 PM, Wes McKinney wrote: >>> Keith (and others), What would you think about creat

Re: [Numpy-discussion] [ANN] Nanny, faster NaN functions

2010-11-21 Thread Keith Goodman
On Sun, Nov 21, 2010 at 10:25 AM, Wes McKinney wrote: > On Sat, Nov 20, 2010 at 7:24 PM, Keith Goodman wrote: >> On Sat, Nov 20, 2010 at 3:54 PM, Wes McKinney wrote: >> >>> Keith (and others), >>> >>> What would you think about creating a library of mostly Cython-based >>> "domain specific funct

Re: [Numpy-discussion] indexing question

2010-11-21 Thread John Salvatier
yes use the symbol ':' so you want t[:,x,y] 2010/11/21 Ernest Adrogué : > Hi, > > Suppose an array of shape (N,2,2), that is N arrays of > shape (2,2). I want to select an element (x,y) from each one > of the subarrays, so I get a 1-dimensional array of length > N. For instance: > > In [228]: t=

Re: [Numpy-discussion] indexing question

2010-11-21 Thread John Salvatier
read about basic slicing : http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html On Sun, Nov 21, 2010 at 11:28 AM, John Salvatier wrote: > yes use the symbol ':' > > so you want > > t[:,x,y] > > 2010/11/21 Ernest Adrogué : >> Hi, >> >> Suppose an array of shape (N,2,2), that is N arrays

[Numpy-discussion] indexing question

2010-11-21 Thread Ernest Adrogué
Hi, Suppose an array of shape (N,2,2), that is N arrays of shape (2,2). I want to select an element (x,y) from each one of the subarrays, so I get a 1-dimensional array of length N. For instance: In [228]: t=np.arange(8).reshape(2,2,2) In [229]: t Out[229]: array([[[0, 1], [2, 3]],