awkward-array | Manipulate arrays of complex data structures
kandi X-RAY | awkward-array Summary
kandi X-RAY | awkward-array Summary
Manipulate arrays of complex data structures as easily as Numpy.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of awkward-array
awkward-array Key Features
awkward-array Examples and Code Snippets
Community Discussions
Trending Discussions on awkward-array
QUESTION
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 row + 1, then filling nans with 0, which works, but I am wondering if there's a better way.
I saw that there's a class AppendableArray that has a .append() function, but I'm not sure how to convert between the two. I'm using awkward 0.12.22, and the data is read out of a ROOT file with uproot 3.11.0
...ANSWER
Answered 2021-May-12 at 23:03Perhaps this is too short to be an answer, but
- Upgrade to Awkward 1.x (you can still import
awkward0
and useak.from_awkward0
andak.to_awkward0
to go back and forth in the same process). - Create an array of single-item lists, perhaps in NumPy (
ak.from_numpy
), perhaps by slicing a one-dimensional array withnp.newaxis
. - Concatenate it with your other array using
ak.concatenate
withaxis=1
. The first dimension needs to be the same (len
of both arrays must be equal), but the second dimensions are unconstrained.
QUESTION
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 modified my tree output to contain two separate branches: one std::vector
with the content, and one std::vector
with the offsets. The contents vector has values pushed into it multiple times between filling the tree. Each time it has values pushed in, the size of the contents vector is stored in the offsets.
My idea was that I would recreate the structure that I need via a nested JaggedArray
when I read the tree. However, reading through the awkward-array documentation, I can't seem to figure out the right way to construct this nested JaggedArray
without looping in python. fromoffsets
requires a 1D index, which means that the jagged indices must be flattened, which then loses their structure. None of the other classmethod
s seem to fit. The example below uses a generator, which I think will be rather slow due to looping in python. Is there a better way to construct the JaggedArray
? Or a better way to store the data in the tree?
ANSWER
Answered 2020-Feb-16 at 18:38You've got the right idea, but ultimately, there isn't a way to convert a jagged ObjectArray
into a doubly jagged array without a "for" loop. The structure of the data requires it.
This is a key issue, though, and it's a reason why some of these algorithms are being ported into C++. The last plot in this talk directly addresses this kind of data (jagged^N of numbers) with a "for" loop moved into C++. This is in development for Awkward 1.0 and Uproot 4.0, which is scheduled to be ready for users at the end of April. (At which point, the conversion of std::vector>
will be automatic, because there's no performance penality anymore.)
At the moment, however, a Python "for" loop, implicitly within fromiter
, is the best you can do.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install awkward-array
You can use awkward-array like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page