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

Daniel Lepage dplepage at gmail.com
Wed Apr 20 14:19:31 EDT 2011


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.copin at 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 at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list