Home > Back-end >  a uniform data structure that can represent an ndarray with various size along a given axis
a uniform data structure that can represent an ndarray with various size along a given axis

Time:05-01

I can use the following code to generate three dimensional array.

import numpy as np
x1 = np.random.rand(8,9,10)

In some scenarios, the studied data set (or array) have various length along the axis 0, In other words. A subset may be of shape (8, 9, 10), and another subset maybe of shape (7,9,10). All these subsets are of the same size along the second and the third axis. If I still want to represent the whole data set using the same data structure, how to achieve this goal?

CodePudding user response:

One solution would be to use awkward-array:
https://github.com/scikit-hep/awkward-1.0

>>> import numpy as np
>>> import awkward as ak

>>> numpy_arrays = [np.random.rand(8,9,10), np.random.rand(7,9,10)]
>>> irregular_array = ak.Array(numpy_arrays)
>>> irregular_array
<Array [[[ ... ]]] type='var * 9 * 10 * int64'>
  • Related