Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reshape with multiple : to allow convenient newaxis #32622

Open
jessebett opened this issue Jul 18, 2019 · 2 comments
Open

reshape with multiple : to allow convenient newaxis #32622

jessebett opened this issue Jul 18, 2019 · 2 comments
Labels
arrays [a, r, r, a, y, s] feature Indicates new feature / enhancement requests

Comments

@jessebett
Copy link
Contributor

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)))

@mbauman
Copy link
Member

mbauman commented Jul 18, 2019

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.

@ararslan ararslan added the arrays [a, r, r, a, y, s] label Jul 18, 2019
@WenyinWei
Copy link

I would appreciate it a lot if this feature can be supported.

@nsajko nsajko added the feature Indicates new feature / enhancement requests label Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] feature Indicates new feature / enhancement requests
Projects
None yet
Development

No branches or pull requests

5 participants