-
so I've been trying to do this:
However, this returns an array with the same first dimension as Thank you for your help! Duc. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Could you give more details, like what the type of When I tried an example, I didn't find anything unexpected: >>> array = ak.Array([[0.0, 1.1, 2.2], [], [3.3, 4.4], [5.5], [6.6, 7.7, 8.8, 9.9]])
>>> array.type
5 * var * float64
>>> array.tolist()
[[0.0, 1.1, 2.2], [], [3.3, 4.4], [5.5], [6.6, 7.7, 8.8, 9.9]] For a singly jagged array of numbers like this, there are two possible masks: flat booleans and (singly) jagged booleans. Here's an example of a flat boolean mask: >>> mask1 = ak.num(array) > 1
>>> mask1.type
5 * bool
>>> mask1.tolist()
[True, False, True, False, True] and here's an example of a jagged boolean mask: >>> mask2 = array * 10 % 2 == 0
>>> mask2.type
5 * var * bool
>>> mask2.tolist()
[[True, False, True], [], [False, True], [False], [True, False, True, False]] When you slice with a flat boolean mask, it has to have the same length as the >>> array[mask1].type
3 * var * float64
>>> array[mask1].tolist()
[[0.0, 1.1, 2.2], [3.3, 4.4], [6.6, 7.7, 8.8, 9.9]] When you slice with a jagged boolean mask, it has to have all the same lengths for each of its nested lists, and it removes numbers from those nested lists: >>> array[mask2].type
5 * var * float64
>>> array[mask2].tolist()
[[0.0, 2.2], [], [4.4], [], [6.6, 8.8]] What happens after that depends on the type and lengths of what the first step returned. For instance, you can have >>> array[mask1, 0]
<Array [0, 3.3, 6.6] type='3 * float64'>
>>> array[mask1][:, 0]
<Array [0, 3.3, 6.6] type='3 * float64'> In my example, I can't get the first item of each list after >>> array = ak.Array([[0.0, 1.1, 2.2], [3.3, 4.4], [5.5], [6.6, 7.7, 8.8, 9.9]])
>>> mask2 = array * 10 % 2 == 1
>>> array[mask2].type
4 * var * float64
>>> array[mask2].tolist()
[[1.1], [3.3], [5.5], [7.7, 9.9]] Now we can pick the second element, but only as a second step: >>> array[mask2][:, 0].type
4 * float64
>>> array[mask2][:, 0].tolist()
[1.1, 3.3, 5.5, 7.7] not as a first step: >>> array[mask2, 0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jpivarski/miniconda3/lib/python3.8/site-packages/awkward/highlevel.py", line 1005, in __getitem__
return ak._util.wrap(self._layout[where], self._behavior)
ValueError: in NumpyArray, too many dimensions in slice
(https://github.com/scikit-hep/awkward-1.0/blob/1.0.2rc4/src/libawkward/array/NumpyArray.cpp#L3925) because Does that help? |
Beta Was this translation helpful? Give feedback.
-
Ah ok, I checked back my codes and I think that's not what went wrong, but it's similar So initially I have a mask array of type: mask = 137178 * bool and then I have two more arrays ( a = a[mask][:,0]
b = b[mask] I would expect them to have the same first dimension but So I based on your response I might be experiencing a bug here? since we would expect the mask to remove lists from |
Beta Was this translation helpful? Give feedback.
Could you give more details, like what the type of
truth_x_target
andmask
are, and what you expected?When I tried an example, I didn't find anything unexpected:
For a singly jagged array of numbers like this, there are two possible masks: flat booleans and (singly) jagged booleans. Here's an example of a flat boolean mask:
and here's an example of a jagged boolean mask: