# Questions tagged [packed-arrays]

Tag for questions about packed arrays. Packed Arrays are data structures that can be seen as monolithic blocks containing a single data type, particularly Integers and Reals. Many functions operate very efficient on packed arrays. Questions may deal with packed array generation, conversion, and usage.

73 questions
Filter by
Sorted by
Tagged with
66 views

### Packed/Unpacked array - what object/like 0 or 1?/how to check/ [duplicate]

In Mathematica, there is a concept called packed array. ...
• 2,877
59 views

### What circumstances would cause memory to inflate while packing the sublists of a ragged matrix?

I'm working with a ragged matrix of considerable size (ByteCount = 47749114088; Length = 563529128). I had seen a suggestion mentioned in other questions (here on StackExchange), that one might be ...
• 2,044
38 views

### Fixing a step size with a variable causes array to be unpacked?

I would expect the following code to produce a packed 11x11x11 element array of 64 bit integers, but it doesn't: ...
59 views

### Unexpected unpacking of wrapped PackedArray

I'm confused as to why the following leads to unpacking of a PackedArray: ...
• 3,040
54 views

### Why is extracting values from an Association with 1 level slower than extracting values from a list of depth 1?

I am not looking for a solution or work-around, but an explanation. Here are six examples of doing a trivial operation on an association and a list. Initially, I was curious about the cost of calling ...
• 2,160
1 vote
72 views

### Unpacking array message in Compile and Fold

Suppose, I have a nonlinear map, like this: ...
• 99
144 views

### Unexpected timing result of Total and Part performance of packed array

Define a = RandomReal[1., {2, 100, 100, 100}]; then Total[a, Infinity]; // RepeatedTiming {0.00183727, Null} and ...
• 15.7k
38 views

### Compression results in unpacking of integers but not reals

Consider the following; Pack some integers. In[287]:= Clear[p5i, p5ic, p5icu, p5r, p5rc, p5rcu] In[288]:= p5i = ToPackedArray@Range@5 Out[288]= {1, 2, 3, 4, 5} ...
1 vote
34 views

### spontaneously quitting kernel, assignment and packed arrays

I am having an issue where the kernel spontaneously quits, deep in a long code that I have used for quite some time without this issue. I've tracked it down to an assignment of the form: a[[All, All, ...
• 1,183
56 views

### Can't initialise packed array of rational numbers [closed]

If I evaluate the following code t = DeveloperToPackedArray[{0, 2/7, -(1/7)}]; DeveloperPackedArrayQ[t] Mathematica returns ...
• 928
128 views

### Why Does Subsets[...,{n}] not Output a Packed List, Even Though it Doesn't Unpack?

Assume list is packed. I expect Subsets[] is a structural operation because it depends on the number of elements, not on what ...
• 1,577
1 vote
68 views

### Excessive usage of memory while using ArrayFlatten or Flatten

I have 16 NxN matrices, where N can be anywhere between 1000-64000.. Some of them are real and some of them are complex. I want to Reshape then to form a 4Nx4N matrix. When I try to accomplish this ...
78 views

### Different timing with large array assignment

Consider the following example n = 10^8; AbsoluteTiming[ A = ConstantArray[1., n]; // anyFunc; A[[2 ;; ;; 2]] = -1.; ] {0.388108, Null} ...
• 6,530
147 views

### Possible speed improvement for numerical linear algebra?

I have a question about further optimising a numerical linear algebra calculation. I've trawled through many useful posts on this site and have ended up with something quite efficient - I was ...
• 109
90 views

### Clarification on how Total[] can be used on multi-dimensional array

I have a rank 5 tensor that ultimately I want to modify so that for the first 3 dimensions, each element is summed together. The result will be a rank 2 tensor whose elements are the summed totals ...
290 views

### Unexpected behavior of the procedure Area on the object 'Polygon'

Bug introduced in 11.3 or earlier and fixed on 12.0. Sometimes get a results, sometimes left unevaluated. For instance ...
• 1,730
632 views

### Is it possible to avoid unpacking when merging Association?

For example, if we have assoc = AssociationThread[{1, 2, 3} -> RandomReal[1., {3, 10}]]; and ...
• 15.7k
367 views

### Avoiding unpacking an array when altering its dimension

I am trying to flatten a matrix from 3-dimensional to 2-dimensional one. The original one has dimension for example {10,120,120}: ...
• 683
120 views

### What changed in String handling between 11.0 and 11.3?

I was trying to optimize some String-handling code here using my standard trick of converting it to a list of bytes first and using basic list operations instead of ...
• 45.5k
126 views

### Why can't (partially) packed arrays be used in this example?

Bug introduced in 11.3 or earlier and persisting through 12.1 or later. Fixed in 13.0.0 or earlier I didn't expect any difference between these: ...
• 1,094
196 views

### How to send packed array from math kernel to 3rd party app via WSTP

Background I'm developing a small python wrapper PyWSTP. The wrapper is still in very early stage and lacking features. One important feature I'm considering is transferring dense array between math ...
• 601
232 views

### Packing and unpacking of arrays with Map/Table

How can I create function, that will not unpack packed arrays with Map/Table. For example I want read bytes from opened stream (this is my original goal): ...
• 796
66 views

### PackedArray version of Chop

I'm a big fan of Chop. It's fast and useful in pre-rounding transforms and things Unfortunately it also necessarily unpacks a real ...
• 45.5k
104 views

### Strange unpacking of a packed array with Insert

In Mathematica 11.1.1, when a packed array is stored within another list, it gets unexpectedly unpacked when Inserting something into the outer list. Create a ...
• 1,253
168 views

### RandomChoice output isn't packed

Why isn't the output of RandomChoice a packed array? For instance: RandomChoice[{.5, .2, .3} -> {1, 2, 3}, 10] DeveloperPackedArrayQ @ % {1, 2, 3, 1, 3, 1, ...
• 124k
145 views

### Fast function to do multiple rectangle region checks

Suppose I have a set of "rectangles" and a set of "points": SeedRandom[5] rects = RandomReal[10, {5, 2, 2}] pts = RandomReal[10, {5, 2}] {{{0.00790584, 0....
• 124k
125 views

### revisit Table unpacking issue

This post is related to my previous post, since that post is ended. I start a new here. Because there is still something I don't understand. define ...
• 15.7k
1 vote
144 views

### Is there a way to reduce size of complex number?

I would like to create huge matrices with hundreds of thousands of elements per side and I would like to use complex numbers in it for further processing by Mathematica functions. When I investigate ...
233 views

### Convert Real packed array of pairs to Complex packed array

I have a Real packed array arr. It may have arbitrary depth but Last@Dimensions[arr] == 2. ...
• 225k
842 views

### How can I determine the type of a packed array?

Packed arrays can be of type Integer, Real or Complex. Knowing that an array ...
• 225k
232 views

### Efficiently create an array of values of a function

I have a function of four arguments, and I would like to have its values on the four-dimensional grid in an array. What is the most efficient way to produce this array, and how do I make it packed? ...
• 281
119 views

### How to efficiently write into PackedArrays that are stored in Associations?

Using Association to generate complicated data types is very comfortable, in particular if one uses those tricks from How to make use of Associations?. However, I ...
• 95.6k
86 views

### Unexpected result of Clip

A simple question. Here Clip works as documented: Clip[0.5, {0, 0}, {0,1}] (* 1 *) Values larger than 0 are replaced with ...
• 9,879
310 views

### Efficient way to replace a value in packed array of integers

When working with integer label matrices returned by such functions as MorphologicalComponents, ImageForestingComponents etc. it ...
• 56.2k
76 views

### Memory optimization for exporting "VideoFrames" with many large Array plots

Suppose you have 5 arrays (normalized by the number of arrays - in this case 5): arrayList = Table[RandomChoice[DeveloperToPackedArray@{-1, 1}, {100, 100}]/5,{5}] ...
1 vote
115 views

### Reap unpacks packed arrays

I noticed that Reap unpacks packed arrays. I've looked at previous answers but am still an unsure whether this a serious issue. E.g. consider Ex 47.3 from EIWL: ...
• 2,632
160 views

### RegionMeasure on packed array crashes Kernel in version 11.1

Bug introduced in 11.1.0 and fixed in 11.1.1 In version 11.1.0, applying RegionMeasure or Area to a region with packed ...
• 56.2k
160 views

• 5,589
231 views

### Getting directly a packed array of repeated packed arrays

Consider this code: Needs["Developer"]; N@Range[5]; PackedArrayQ@% Table[%%, 5]; PackedArrayQ@% which prints True, ...
• 1,547
2k views

### Fast way to export large amount of data in "Table" format

I have about a million 3D points, say data = Table[{1. x, 1. y, 0.}, {x, 1000}, {y, 10^3}]~Flatten~1; I want to visualize them, but ...
• 5,589
84 views

### Nested list can not be packed?

Why can't nested list be packed? In[252]:= ftest = {1., {3.}}; ftest = DeveloperToPackedArray[ftest]; Developer`PackedArrayQ[ftest] Out[254]= False
• 1,548
338 views

### Why does Outer sometimes return a packed array, and sometimes not?

For example In[342]:= test3 = Flatten[Outer[Plus, Range[1000], Range[1000]], 1]; // AbsoluteTiming Out[342]= {0.0198735, Null} returns PackedArray (...
• 15.7k
344 views

### Speed up construction of a dense matrix

I wish to find the numerical eigenvalues of a relatively small (100 dimensional) Hermitian matrix. While the eigenvalue calculation itself is fast, the construction of the matrix is taking longer than ...
• 749
161 views

### Why are so many built-in numerical function doesn't check its argument is packed array or not? [closed]

This question is brought by this one. Outer[Times, RandomReal[1., 1000000], {1., 2.}]; is much slower than ...
• 15.7k