getting all the position of minimum in an awkward array

190 Views Asked by At

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 possible to get all the indices.

>>> a1=ak.Array([[], [], [1, 1, 0, 1, 1, 0, 0], [], [], [], [], [0, 0], [], [-1, -1, -1, -1]])
>>> ak.to_list(ak.argmin(a1,axis=-1, keepdims=True))
[[None], [None], [2], [None], [None], [None], [None], [0], [None], [0]]

What I need as an output is:

[[None], [None], [2,5,6], [None], [None], [None], [None], [0,1], [None], [0,1,2,3]]

In similar lines, in addition of argmin or argmax, it is possible to do something like argN(array, number, axis=-1, keepdims=True), where it can become argmin when number = 0 and argmax when number = 1, for this particular case.

I tried to look at ak.where but I could not get any hint if it feasible using ak.where. Documentation says, ak.where will accept ak.Array of booleans

>>> a1==1

<Array [[], [], ... False, False, False]] type='10 * var * bool'>

Hence I tried:

>>> ak.where((a1==1))

And the error I get is: return to_numpy(array.toRegularArray(), allow_missing=allow_missing) ValueError: in ListOffsetArray64, cannot convert to RegularArray because subarray lengths are not regular

(https://github.com/scikit-hep/awkward-1.0/blob/0.3.1/src/cpu-kernels/operations.cpp#L902)

0

There are 0 best solutions below