2
$\begingroup$

I am trying to understand why I am seeing inconsistent results when using ArrayReshape on a SparseArray vs. a normal nested List. For example, define a sample 2x2x2x2 array and its SparseArray representation (which needn't be actually sparse):

Matrix = RandomReal[{0, 1}, {2, 2, 2, 2}];
SparseMatrix = SparseArray@Matrix;

Both Dimensions@Matrix and Dimensions@SparseMatrix give {2,2,2,2} as expected. However, while

Dimensions@ArrayReshape[Matrix, {4, 4}]

gives {4, 4} as expected, in my system (clean 11.2.0.0 kernel on Windows 10) running

Dimensions@ArrayReshape[SparseMatrix, {4, 4}]

gives {8, 2}, which is quite odd. Is this a bug, or expected behavior? am I missing something here?

$\endgroup$
  • $\begingroup$ I cannot reproduce this issue with version 11.3 for macOS. The exprected behavior is of course an array of dimensions {4, 4}. $\endgroup$ – Henrik Schumacher Jun 13 '18 at 10:41
  • $\begingroup$ version 9.0 (Windows 10 64 bit) also gives {4,4}. $\endgroup$ – kglr Jun 13 '18 at 10:43
  • $\begingroup$ ... and so does version 11.0.1 for macOS. $\endgroup$ – Henrik Schumacher Jun 13 '18 at 16:00
  • $\begingroup$ And both v10.4 and v11.3 on Linux give the correct answer, {4, 4}, for both instances. $\endgroup$ – corey979 Jun 13 '18 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.