I'm trying to optimise my code by making us of packed array. However, it appears that using Set in combination with Part sometime unpacks the array, and sometimes leaves the array packed, even when the data you put in is of the same type.

When does Set unpack an array?

Here is an example:


  • $\begingroup$ Please give examples of cases when it unpacks. It never unpacks for me when the type matches. $\endgroup$
    – Szabolcs
    Oct 28, 2016 at 16:05
  • $\begingroup$ I added an example $\endgroup$
    – user44136
    Oct 28, 2016 at 16:26
  • 1
    $\begingroup$ {1., 0., 0.} is not packed. I suspect that if you give it packed, with Developer`ToPackedArray[{1., 0., 0.}], then init will remain packed. Can you try this? $\endgroup$
    – user31159
    Oct 28, 2016 at 16:28

1 Answer 1


See my answer here. The right hand side of the assignment has to be a packed array.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.