I have an array df in which each element is a list of 2 numbers. Given an element p = [18, 169]. I would like to find the indices of such elements p in df. Given df
[[[13, 169], [18, 169], [183, 169]],
[[-183, 169], [18, 169], [183, 169]],
[[18, 169], [-18, 169], [183, 169]]]
With (df == p).all(-1), I get
array([[False, True, False],
[False, True, False],
[ True, False, False]])
What I want is
[[0, 1],
[1, 1],
[2, 0]]
Could you please elaborate on how to do so?
import numpy as np
df = np.array([[[13, 169], [18, 169], [183, 169]],
[[-183, 169], [18, 169], [183, 169]],
[[18, 169], [-18, 169], [183, 169]]])
p = [18, 169]
ind = (df == p).all(-1)
ind
dfis not a 2D array, but a 3D array. You can check this via:df.ndim, which returns3.np.stack(np.where((df == p).all(-1))). It produces what I'm looking for. I wonder why you deleted it.