Rationale for adding singleton dim

Hi.

What is the rationale for adding a singleton dimension in the following commands:

julia> A=rand(3,3);A[:,[2 1 3]]
3×1×3 Array{Float64, 3}:
[:, :, 1] =
 0.7056166212562252
 0.6016873438276988
 0.8375543887468311

[:, :, 2] =
 0.7127858488837275
 0.2064595407727965
 0.12457389352665937

[:, :, 3] =
 0.6390464694720495
 0.12757073495030102
 0.9146866678160415

Is there a different way (besides using dropdims a posteriori) to obtain a 3x3 matrix instead ? Thanks.

S.

A[:,[2, 1, 3]] # index columns using a vector of indices (not a matrix)

Thanks. I got to get rid of (bad) Scilab/Matlab habits…

S.

1 Like

For the rationale, see this great post.

2 Likes