Re: [Numpy-discussion] Suggestion: Add the unsqueeze function to numpy

2011-04-20 Thread josef . pktd
On Wed, Apr 20, 2011 at 2:19 PM, Daniel Lepage wrote: > You can also insert new axes when you slice an array via np.newaxis, fwiw: > import numpy as np x = np.random.random((3,4,5)) y = x.mean(axis=1) y.shape > (3, 5) y[:,np.newaxis,:].shape > (3, 1, 5) That's convenient

Re: [Numpy-discussion] Suggestion: Add the unsqueeze function to numpy

2011-04-20 Thread Bruce Southey
On 04/20/2011 12:24 PM, Yannick Copin wrote: > gmail.com> writes: >> I also proposed this already once. >> >> However there is already function in numpy (where I have often >> problems remembering the name): >> >> numpy.expand_dims(a, axis) > Ah, thanks for the tip, I didn't know this one. Th

Re: [Numpy-discussion] Suggestion: Add the unsqueeze function to numpy

2011-04-20 Thread Daniel Lepage
You can also insert new axes when you slice an array via np.newaxis, fwiw: >>> import numpy as np >>> x = np.random.random((3,4,5)) >>> y = x.mean(axis=1) >>> y.shape (3, 5) >>> y[:,np.newaxis,:].shape (3, 1, 5) -- Dan Lepage On Wed, Apr 20, 2011 at 1:24 PM, Yannick Copin wrote: >   gmail.com>

Re: [Numpy-discussion] Suggestion: Add the unsqueeze function to numpy

2011-04-20 Thread Yannick Copin
gmail.com> writes: > I also proposed this already once. > > However there is already function in numpy (where I have often > problems remembering the name): > > numpy.expand_dims(a, axis) Ah, thanks for the tip, I didn't know this one. The name is unfortunate indeed... Cheers, Yannick _

Re: [Numpy-discussion] Suggestion: Add the unsqueeze function to numpy

2011-04-20 Thread josef . pktd
On Wed, Apr 20, 2011 at 6:27 AM, Yannick Copin wrote: > Hi, > > I'm a very frequent user of the following "unsqueeze" function, which I > initially copied from scipy/stats/models/robust/scale.py and which seems to be > also present in scikits.statsmodels.tools.unsqueeze. Would it be possible to >

[Numpy-discussion] Suggestion: Add the unsqueeze function to numpy

2011-04-20 Thread Yannick Copin
Hi, I'm a very frequent user of the following "unsqueeze" function, which I initially copied from scipy/stats/models/robust/scale.py and which seems to be also present in scikits.statsmodels.tools.unsqueeze. Would it be possible to include it natively to numpy? def unsqueeze(data, axis, oldsha