You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to get the behaviour of np.newaxis which allows for quickly creating a new axis in a multidimensional array.
e.g.
X = randn(4,5,6)
Y = X[:,:,np.newaxis,:]
size(Y) == (4,5,1,6)
this is very commonly used in machine learning dimension munging.
Issue #16790 allowed adding a single : to reshape to omit a single dimension.
In this issue I would like to discuss if a possible solution to convenient newaxis functionality would be to also allow reshape to accept the number of Colons equal to the number of dimensions (i.e. length(size(X))).
For example, the above newaxis will be achieved by: reshape(X,(:,:,1,:))
which would have identical behaviour to @ararslan's solution: reshape(X,(size(X,1),size(X,2),1,size(X,3)))
The text was updated successfully, but these errors were encountered:
We do have a built in np.newaxis — it’s spelled [CartesianIndex()]. We could just name that something reasonable and export it... although you need to use it in conjunction with views and so we’d want a little bit of special support to make these sorts of views fast.
I am trying to get the behaviour of
np.newaxis
which allows for quickly creating a new axis in a multidimensional array.e.g.
this is very commonly used in machine learning dimension munging.
Issue #16790 allowed adding a single
:
toreshape
to omit a single dimension.In this issue I would like to discuss if a possible solution to convenient
newaxis
functionality would be to also allowreshape
to accept the number ofColon
s equal to the number of dimensions (i.e.length(size(X))
).For example, the above
newaxis
will be achieved by:reshape(X,(:,:,1,:))
which would have identical behaviour to @ararslan's solution:
reshape(X,(size(X,1),size(X,2),1,size(X,3)))
The text was updated successfully, but these errors were encountered: