Julia: Allow : in reshape

Created on 6 Jun 2016  Â·  12Comments  Â·  Source: JuliaLang/julia

I find myself writing a lot of this:

A = reshape(A, N, div(length(A), N))

Instead, I'd like to write

A = reshape(A, N, :)
arrays

Most helpful comment

I can revamp that PR, but maybe one of the array experts like @mbauman or @timholy can way in on what they think of this idea.

All 12 comments

IIRC, Python uses a -1 to achieve what you propose. I have to say that I never really liked it so much, and : looks way cleaner.

More generally,

B = reshape(A,  N1, N2, N3, :)

etc; (should be a fairly easy hack?)

Yes I love this. Have wanted it so many times.

Even more generally, allow a single colon in any position:

B = reshape(A, N1, :, N3, N4)

Should still be perfectly implementable.

I remember proposing this a while ago in some issue and it wasn't generally liked.

I forget what the objection was before. Seems like a reasonable thing to me. It's possible that it was before : became a thing we could dispatch on.

didn't : use to have to be handled by the parser until not that long ago?

sorry I missed PR - anyhow it would be great if this feature could now be added

I can revamp that PR, but maybe one of the array experts like @mbauman or @timholy can way in on what they think of this idea.

+1. I think it's handy and useful. That's why I tried resurrecting your PR… but it got no traction at the time. Anyone's welcome to update either of my old commits and try it again. At a minimum the tests should be useful.

I feel like this is a common usage pattern and would be nice to have in Julia. MATLAB, for example, uses empty [] to tell reshape to compute the missing dimension: https://www.mathworks.com/help/matlab/ref/reshape.html#examples

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Keno picture Keno  Â·  3Comments

omus picture omus  Â·  3Comments

TotalVerb picture TotalVerb  Â·  3Comments

musm picture musm  Â·  3Comments

manor picture manor  Â·  3Comments