Questions tagged [awkward-array]

Python toolkit for manipulating nested data structures as though they were NumPy arrays.

awkward is a Python library for computing array-at-a-time ("vectorized") operations on nested and irregular-length data structures. The interface resembles as much as possible and is implemented using NumPy.

It is intended as an interactive analysis toolkit for datasets that can't be reduced to rectilinear arrays. For example, a dataset of extrasolar planets can have arbitrarily many planets per star, and each planet has several attributes. A dataset of particle physics collisions contains collision event records, each with arbitrarily many electron records, muon records, photon records, etc. Instead of looping over these constructs in a general purpose language, awkward-array allows the user to slice them like (irregular) multidimensional arrays, project through columns, sum over variable-sized sets, etc.

As an artificial example, consider this structure:

complicated = awkward.fromiter(
    [[1.21, 4.84, None, 10.89, None],
     [19.36, [30.25]],
     [{"x": 36, "y": {"z": 49}}, None, {"x": 64, "y": {"z": 81}}]
    ])

Once in awkward form, we can apply Numpy operations, such as ufuncs:

numpy.sqrt(complicated).tolist()
# [[1.1, 2.2, None, 3.3000000000000003, None],
#  [4.4, [5.5]],
#  [{'x': 6.0, 'y': {'z': 7.0}}, None, {'x': 8.0, 'y': {'z': 9.0}}]]

awkward-array interfaces with , , , , and .

68 questions
3
votes
1 answer

Writing Trees, number of baskets and compression (uproot)

I am trying to optimize the way trees are written in pyroot and came across uproot. In the end my application should write events (consisiting of arrays) to a tree which are continuously coming in. The first approach is the classic way: event=…
Jailbone
  • 83
  • 6
3
votes
2 answers

Changing an awkward array's values' type from float to int

I have an awkward array of type float and I need it to be of type int. Something equivalent to the following numpy snippet: import numpy as np import awkward as ak arr = np.array([1., 2., 3.]) arr = arr.astype(int) arr2 = ak.Array(np.array([1.,…
HEP N008
  • 187
  • 8
3
votes
1 answer

Awkward Array: How to get numpy array after storing as Parquet (not BitMasked)?

I want to store 2D arrays of different length as an AwkwardArray, store them as Parquet, and later access them again. The problem is that, after loading from Parquet, the format is BitMaskedArray and the access performance is a bit slow.…
NumesSanguis
  • 5,832
  • 6
  • 41
  • 76
2
votes
3 answers

Is there an easy way to find the maximum depth of a jagged array in the awkward python library?

Say we have a jagged array that looks like this: arr = ak.Array([[1, 2, 3], [3, 2], [], [5], [6, 9, 6, 9]]) We can see that it has a depth of 2. Is there something like a single or combination of built-in functions that would tell me that? ak.size…
aaportel
  • 471
  • 1
  • 3
  • 6
2
votes
1 answer

Can I recalculate the energy of an awkward array of Vectors by declaring a new mass value?

My question is about the Vector module in scikit-hep. https://vector.readthedocs.io/en/latest/index.html I have an awkward array of vectors and I'd like to set the mass of all of them to be a common value. For example, I can do this with a single…
Matt Bellis
  • 289
  • 2
  • 10
2
votes
2 answers

Convert array of varying sized arrays to numpy array

I am working with a root file (array of arrays). When I load the array into python, I get an awkward array since this is an array of arrays of varying sizes. I would like to learn how to convert this to a numpy array of arrays of the same size, by…
Dizzy
  • 33
  • 3
2
votes
1 answer

append an element to every row of a jagged array

I am trying to add a 0 to every row of a jagged array. I want to go from to so that when I grab the -1th index, I get 0. Currently I'm padding every row to the length of the biggest…
2
votes
1 answer

Issue in importing awkward array package: DLL load failed while importing _ext

I am trying to use awkward in my Windows 10 system. I am using python 3.8.2. After installing the package, when I import it, I am getting this DLL import error. >>> import awkward as ak Traceback (most recent call last): File "", line 1, in…
MSS
  • 3,306
  • 1
  • 19
  • 50
2
votes
1 answer

Using awkward1.Array for BDT

I want to implement a boosted decision tree for my analysis. But the entries in my array contain are of varying length, so the array is not convertible directly into numpy or pandas. Is there any way to use existing ML libraries with awkward array?
2
votes
2 answers

Reshape Array in Array in Array

I have a root file that I open with 2000 entries, and variable amount of subentries and in each column is a different variable. Lets say I am only interested in 5 of those. I want to put them in an array with np.shape(array)=(2000,250,5). The 250 is…
2
votes
1 answer

removing none from an awkward array

I have an awkward array (1) which I obtained post-processing. An array look like: >>> ak.Array([96., 99., 67., 13., 3., None, 1., 1.,None]) I want to remove the None elements from this array. I could remove them using loop, but I want to avoid…
Raman Khurana
  • 125
  • 1
  • 7
2
votes
2 answers

Error when using awkward array 1.0 combinatorics function to make two-particle combinations

I'm running into some trouble when using awkward array 1.0 to make combinations of particles with ak.combinations. I see the error when trying to do ak.unzip on the combinations I have made (following the tutorial here:…
dhill89
  • 61
  • 4
2
votes
1 answer

How to use np arrays as a mask for jagged arrays (python - awkward)?

I have a root file from which I would like to extract a certain candidate per event. On the other hand, I have a numpy array containing the index of the candidate I want to extract. Let's say that my root file has the following branch: branch =…
Horace
  • 62
  • 4
2
votes
1 answer

Combine awkward-array JaggedArray contents and offsets into nested JaggedArray

I'm trying to use the excellent uproot and awkward-array to read some analysis data stored in a TTree. I understand that ROOT doesn't write nested vectors (ie. std::vector>) in a columnar format, but following this discussion, I…
2
votes
1 answer

AwkwardArray: Possible to append an array to an exisitng Parquet file?

Is it possible with AwkwardArray (awkward0) to append to an existing parquet file (written by AwkwardArray)? Normal Awkward Parquet storing The following code creates a Parquet file with inside a few Awkward arrays (e.g. audio data): import numpy as…
NumesSanguis
  • 5,832
  • 6
  • 41
  • 76
1
2 3 4 5