Replies: 1 comment
-
If I understand your question, you have an array It would be good to understand more about your problem; the shapes and dimensions of the arrays are important. But, we can make a start! What it seems like you want to do is to build an index that can pull out the proper elements of import awkward as ak
import numpy as np
flat_a = ak.flatten(a)
shape_a = ak.num(a)
flat_b = ak.flatten(b)
masked_flat_a = flat_a.mask[flat_a == 1]
flat_index = np.cumsum(masked_flat_a) - 1
flat_result = flat_b[flat_index]
result = ak.unflatten(flat_result, shape_a)
result This code sample flattens both arrays (preserving the shape of This solution uses Awkward's ragged indexing feature, which is very powerful. |
Beta Was this translation helpful? Give feedback.
-
Hello Experts,
I was trying to do an operation as described in the following:
I have two arrays
Now, I want to merge
b
toa
where the value1
matches. I mean I want to have something like this:c = [ [], [12.4], [23.5], [] ]
The reason is the following:
I had some awkward arrays in the beginning. In order to do some existing operations, I had to convert it to numpy and, thats why I applied a mask to make that array regular. But, I saved the places where the new elements should be placed.
Please let me know if there is any way to do the same.
Thank you very much
Gourab
Beta Was this translation helpful? Give feedback.
All reactions