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
<yannick.co...@laposte.net> wrote:
>  <josef.pktd <at> 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
>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to