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
1
vote
2 answers

Use a multidimensional index on a MultiIndex pandas dataframe?

I have a multiindex pandas dataframe that looks like this (called p_z): p_z entry subentry 0 0 0.338738 1 0.636035 2 -0.307365 3 -0.167779 4 0.243284 ... …
HEP N008
  • 187
  • 8
1
vote
1 answer

awkward1; how to set array dimension as variable?

So aim is I'm trying to save some arrays as parquets. I can use a python debugger to reach the point in my code that they are ready for saving. Inside my complicated mess of code they look like; ipdb> ak.__version__ '1.2.2' ipdb> array1
Clumsy cat
  • 289
  • 1
  • 12
1
vote
1 answer

How to remove a field from a collection of records created by awkward.zip?

So a collection of records has been created using awkward.zip; import awkward pineapple = awkward.from_iter([3, 4]) tofu = awkward.from_iter([5, 6]) pizza = awkward.zip({"pineapple": pineapple, "tofu": tofu}) I'd like to remove one of the…
Clumsy cat
  • 289
  • 1
  • 12
1
vote
1 answer

Why can't we convert flat columns of awkward1 arrays `to_parquet`?

A follow up from this question; Best way to save a dict of awkward1 arrays? To save multiple columns of nested awkward1 arrays (with varying length); import awkward1 as ak dog = ak.from_iter([[1, 2], [5]]) cat = ak.from_iter([[4]]) pets =…
Clumsy cat
  • 289
  • 1
  • 12
1
vote
1 answer

Best way to save a dict of awkward1 arrays?

So back in awkward v0 it was possible to do; import awkward dog = awkward.fromiter([[1., 2.], [5.]]) cat = awkward.fromiter([[4], [3]]) dict_of_arrays = {'dog': dog, 'cat': cat} awkward.save("pets.awkd", dict_of_arrays) Then we could lazy load the…
Clumsy cat
  • 289
  • 1
  • 12
1
vote
1 answer

How can I use the Numba with boolean in coffea framework?

@numba.njit def make_vid_plot(Photon): hoe_arr=[] sieie_arr=[] Isochg_arr = [] for eventIdx,pho in enumerate(Photon): for phoIdx,_ in enumerate(pho): vid = Photon[eventIdx][phoIdx].vidNestedWPBitmap vid_cuts1 =…
jiwoong
  • 19
  • 1
1
vote
1 answer

Get all attributes with common name on different levels in Awkward array

Does the awkward library provide a way to slice out all attributes of a given name, regardless of the level? I was thinking something like this: import awkward as ak obj = { 'resource_id': 'abc', 'events': [ {'resource_id': '123',…
derchambers
  • 904
  • 13
  • 19
1
vote
3 answers

filtered elements in jagged list in nested dictionary using awkward

I have a large nested dictionary with jagged list 'c' : x = {'first_block': {'unit1': {'a': (3,5,4), 'b': 23, 'c': [10]}, 'unit2': {'a': (5,8,7), 'b': 15, 'c': [20,10]}, 'unit10k': {'a': (2,4,9), 'b': 10, 'c': [6,10,20,5]}}, …
SeanD
  • 105
  • 1
  • 1
  • 7
1
vote
1 answer

Efficient method to replace values in awkward array according to a dictionary?

I have a dictionary with integer keys and float values. I also have a 2D awkward array with integer entries (I'm using awkward1). I want to replace these integers with the corresponding float according to the dictionary, keeping the awkward array…
1
vote
1 answer

awkward array ak.unzip behaviour

When I acess a root file and extract the data I want like in following example: events=uproot.open(filename)["btagana/ttree;6"] …
1
vote
1 answer

Error when using an awkward array with an index array

I currently have a list of values and an awkward array of integer values. I want the same dimension awkward array, but where the values are the indices of the "values" arrays corresponding with the integer values of the awkward array. For…
HEP N008
  • 187
  • 8
1
vote
2 answers

Simulate numpy.cumsum at the deepest level of a JaggedArray

I have a singe level nested array, and I'd like to calculate the running sum at the deepest level:
Gordon
  • 3,012
  • 2
  • 26
  • 35
1
vote
1 answer

Awkward array add attributes in intervals

I want to extract data out of a root file and get it into shape to end with a numpy array/tensor to fill it into a neural-network. I am already able to get the track data I want in shape with a padding to convert it into a numpy array, but I want…
1
vote
1 answer

Implementing numpy.linalg.norm for awkward-arrays

At the moment, no implementation exists for numpy.linalg.norm with akward-arrays. In awkward1 I can use behavior to overwrite (or add?) implementations as shown in the tutorial. In my use-case I have successfully implemented versions of np.absolute…
DragonTux
  • 732
  • 10
  • 22
1
vote
0 answers

getting all the position of minimum in an awkward array

I have an awkward1 array from which I want to extract the all positions of minimum and maximum. However, when I used the following I can extract only the first occurrence, not all of them. Is it possible to get all the indices. >>> a1=ak.Array([[],…
Raman Khurana
  • 125
  • 1
  • 7