I have a list like this,
mylist = [
np.array([48.5, 38.0, 40.0]),
np.array([61.5, 52.5, 55.5, 46.5]),
np.array([35.5, 36.5]),
]
I want to find the index of the array, and the location of the specific value in the array together with the values in mylist.
I am able to achieve the last column with np.concatenate(mylist) but don't know how to handle the rest efficiently.
expected = np.vstack(
(
np.array([0, 0, 0, 1, 1, 1, 1, 2, 2]),
np.array([0, 1, 2, 0, 1, 2, 3, 0, 1]),
np.array([48.5, 38.0, 40.0, 61.5, 52.5, 55.5, 46.5, 35.5, 36.5]),
)
).T
It can be read as i.e. 38 is in the first array (index=0) and it is the second element of that array (index = 1).
[0]*len(mylist[0]) + [1]*len(mylist[1]) + [2]*len(mylist[2]), and the second is[range(len(mylist[0]))]+[range(len(mylist[1]))]+[range(len(mylist[2]))]. No need to go searching.