-
Hello, dear community! I'm trying to solve the following issue: I have data about a particle cloud in a NumPy array with shape (1250,91,19) where the first index is related to the number of events(1250) and the other two with the rows (particles) and columns (particles features) of my data. Each event has a variable number of particles, the event with the highest number has 91 particles. Because of this zero padding was used to fill the rows up to 91. I converted this NumPy array to an awkward array and now I'm trying to get rid of the rows filled with zero. I tried to assign to each "zero" a None element and after this use the
but this attempt would be an In-place assignment, which isn't supported as a design choice. Is there any way to remove an entire row similar to An example of the structure of the events can be found in the following file: My apologies if this is a simple question, I've searched for some solution, but I found only the "None element" one. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I have to make some assumptions here; let me know if they are wrong!
What you probably want to use here is Awkward's ragged indexing. We'll construct an array that indexes up to the second dimension, and ignore the empty rows. First, let's convert the array to an Awkward Array array = ak.from_numpy(input_events) Now we can identify which rows are not padding, according to their second element row_is_not_padding = array[:, :, 1] != 0 Subsequently, we can keep only these rows. We need to convert the index into a ragged array, so that Awkward's ragged indexing takes place. I.e., to go from >>> row_is_not_padding.type.show()
1250 * 91 * bool to >>> ak.from_regular(row_is_not_padding).type.show()
1250 * var * bool Finally, we can index into the array with this ragged index array_ragged = array[
ak.from_regular(row_is_not_padding)
] The result has a ragged shape: >>> array_ragged.type.show()
1250 * var * 19 * float64 |
Beta Was this translation helpful? Give feedback.
I have to make some assumptions here; let me know if they are wrong!
array[:, :, 1]
) is zero if that "row" (axis=1) is missing.1250 * var * 19
, i.e. your final dimension is regular of length 19.What you probably want to use here is Awkward's ragged indexing. We'll construct an array that indexes up to the second dimension, and ignore the empty rows.
First, let's convert the array to an Awkward Array
Now we can identify which rows are not padding, according to their second element