Questions tagged [awkward-array]
Python toolkit for manipulating nested data structures as though they were NumPy arrays.
64
questions
1
vote
1
answer
28
views
Creating a new Awkward array from indices
The problem I am facing is to create a new array from a set of indices. Namely, I have a set of particles and jets, for each jet there is a list of indices of which particles belong to the given jet.
...
1
vote
1
answer
33
views
how to add new field in a 'zip' jagged array
I want to add a new field in an already zipped jagged array. For example, if I zip 4D info into a muons object, then I can call pt,eta,phi,charge like this: muons.Muon.pt. However, if I want to add a ...
1
vote
1
answer
27
views
Is there an analog of coffea.processor.PackedSelection() for jagged array masks?
So in a coffea processor, I've implemented a series of cuts on the object level using a dictionary of jagged truth arrays, where each item is just a cut; think cuts['etacut'] = abs(events....
2
votes
3
answers
53
views
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 ...
1
vote
2
answers
97
views
filtering "events" in awkward-array
I am reading data from a file of "events". For each event, there is some number of "tracks". For each track there are a series of "variables". A stripped down version ...
0
votes
0
answers
32
views
Unpacking a variable number of 2D jagged numpy tuples (findcontours())
I'm using cv2.findcontours() which outputs a variable number of variable length Nx2 tuples.
For example, converting the tuples to a list:
(array([[[100, 100]], ..., [[200, 200]]], dtype=int32), ...
2
votes
1
answer
77
views
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 ...
1
vote
1
answer
95
views
Using awkward-array with zip/unzip with two different physics objects
I'm trying to reproduce parts of the Higgs discovery in the Higgs --> 4 leptons channel with open data and making use of awkward. I can do it when the leptons are the same (e.g. 4 muons) with zip/...
0
votes
0
answers
231
views
Rebinning a TH2 histogram from ROOT using uproot and then plot it with matplotlib
I am able to extract a TH2 histogram from ROOT using the h = f[...].to_numpy() of uproot.
This I can then plot with mplhep as a hist2dplot(h).
However, I have the problem that I would like to rebin ...
1
vote
0
answers
81
views
Comparing arrays for equality with condition on one entry
Let's say I have a "Truth" array:
a = [1,2,3]
and I want to compare it to b for equality with
b = [1,2,3]
awkward.all(a == b)
Easy enough. Now we want this to be a general code which works ...
3
votes
1
answer
174
views
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.
...
1
vote
1
answer
76
views
Using `dask` to fill `boost_histograms` stored in class in parallel
I have an dask -boost_histogram question. I have a code structure as follows:
I have a class defined in some script:
class MyHist:
def __init__(....):
self.bh = None
def make_hist(.....
1
vote
1
answer
159
views
TLorentz vector features in uproot4/vector when calculating invariant mass of a jet
I wish to sum all the 4-momenta of the constituents in a jet. In uproot3 (+ uproot3-methods) there was the functionality of creating a TLorentzVectorArray and just doing .sum()
So this worked fine:
...
2
votes
2
answers
454
views
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 ...
1
vote
2
answers
326
views
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 ...
2
votes
1
answer
142
views
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
<JaggedArray [[1 2 3] [1 2]]>
to
<JaggedArray [[1 2 3 0] [1 2 0]]>
so that when I grab the -1th index, I get 0. ...
1
vote
1
answer
82
views
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&...
1
vote
1
answer
129
views
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": ...
1
vote
1
answer
135
views
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], [...
1
vote
1
answer
237
views
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("...
2
votes
1
answer
918
views
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
...
1
vote
1
answer
79
views
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 ...
1
vote
1
answer
118
views
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]...
0
votes
1
answer
544
views
TLorentz vector in Uproot 4
I try to use TLorentz vector in uproot4.
But I found that methods in "uproot_methods" module are now worked with Awkward High level array.
Error message # -----------------------------------...
1
vote
1
answer
42
views
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',
...
1
vote
3
answers
298
views
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': ...
1
vote
1
answer
403
views
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 ...
1
vote
1
answer
66
views
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"]
jet_data=events.arrays(filter_name=["Jet_nFirstTrack&...
2
votes
2
answers
272
views
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 = ...
1
vote
1
answer
390
views
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 ...
1
vote
2
answers
91
views
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:
<JaggedArray [[0.8143442176354316 0.18565578236456845] [1.0] [0.8029232081440607 0....
1
vote
1
answer
203
views
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 ...
1
vote
1
answer
280
views
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 ...
2
votes
2
answers
225
views
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 ...
1
vote
0
answers
98
views
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 ...
1
vote
1
answer
85
views
ak.add function similar to np.add
Do we already have a function similar to np.add in awkward arrays?
I am in a situation i need to add them, and "+" operator work fine for simple array but not for nested array.
e.g.
>>&...
0
votes
1
answer
106
views
Cartesian (cross) products and np.unique()
Depending on your few on my approach this is either a question about using np.unique() on awkward1 arrays or a call for a better approach:
Let a and b be two awkward1 arrays of the same outer length (...
2
votes
1
answer
365
views
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 ...
0
votes
2
answers
120
views
while loop equivalent function/snippet in awkward array
I have a function which I would like to convert so that i can use with awkward array 1.
Function following which used to work for float but not for awkward arrays for the known reasons.
def ...
1
vote
1
answer
230
views
Plotting with different length of jagged arrays
I have a problem when trying to plot 2d histogram or graph with different length of jagged arrays.
Here is a simple example. Suppose there are 7 events of gen-level pT and its Et.
pT = [ [46.8], [31.7]...
2
votes
2
answers
54
views
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 ...
0
votes
2
answers
542
views
Convert list of tuples in list of lists ( NP array )
i have a array response from a api and i got this poly:
poly = [(0,525),(961,525),(961,1003),(0,1003)]
i need to multiply each item for 0.35, them my code was it:
poly = ak.Array(poly) * (35/100)
i ...
2
votes
1
answer
293
views
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 ...
1
vote
0
answers
72
views
How to resolve TypingErrors when the property of an ak.Array subclass relies on Numba-compiled functions?
I've perused the docs and demo notebooks in the awkward1 repo (and it's entirely possible I missed something obvious), but I've strayed into unfamiliar territory and would like some help.
Suppose I ...
0
votes
1
answer
187
views
Awkward-array test for elements of one JaggedArray in another
I need to perform a calculation on a JaggedArray, but only if the elements in the JaggedArray are in contained in another JaggedArray. I'd like to receive back a mask with True if the element in is ...
0
votes
0
answers
169
views
Python AwkwardArray: How to define a cyclic array?
I have been searching for a way to create a:
Bounded
Cyclic
Contiguous
numpyable API'ed
array.
I came across AwkwardArray, but was not able to make sense of the doc, which is very verbose, but ...
1
vote
0
answers
76
views
Appending columns to awkward.Table
I am trying to append new columns to an existing awkward Table. The README said that this is possible, but I can't find the way. For example I have a table
df = awk.Table(
p = ppkf2,
...
1
vote
1
answer
71
views
how to copy a jagged array in awkward-array
In awkward0 I would like to separately persist various selections of a table
in pseudo code
X = awkward.Table(...)
one_jet = X[X.n_jet == 1]
two_jet = X[X.n_jet == 1]
awkward.save(one_jet)
awkward....
1
vote
0
answers
78
views
Is there a way to stack JaggedArrays without fromiter()?
I have two 2D JaggedArrays of the same length (in axis=0) that I'd like to stack in axis=1. For example:
a = awkward.fromiter([[0], [3, 4]])
b = awkward.fromiter([[1, 2], [5]])
and I want to get ...
2
votes
1
answer
188
views
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<std::vector<int>>...