Bug introduced in 11.0 and fixed in 11.3.0
I am trying to reshape a $2 \times 2 \times 2$ array into a $n \times m$ array. It seems that if the matrix is defined via SparseArray
, the ArrayReshape
command doesn't care what $n$ and $m$ I choose, it always reshapes it to a $4 \times 2$ array.
In this code I try to reshape to $1 \times 8$:
Clear["Global`*"]
m = SparseArray[{i_, i_, i_} -> 1., {2, 2, 2}];
mt = ArrayReshape[m, {1, 8}];
MatrixForm[mt]
$\begin{pmatrix}1.&0.\\ 0.&0.\\0.&0.\\0.&1.\end{pmatrix}$
Why does it work like that? Am I doing something wrong?
SparseArray
, despite what the docs say.Dimensions@ArrayReshape[m, {1, 8}]
gives{4, 2}
, butDimensions@ArrayReshape[Normal@m, {1, 8}]
gives{1, 8}
. $\endgroup${1,8}
dimensional) $\endgroup$