Consider the code
import numpy as np
v = np.linspace(0, 9, 10)
w = np.array([3.5, 4.5])
idx = np.searchsorted(v, w)
v = np.insert(v, idx, w)
print(idx, v[idx])
which outputs
[4 5] array([3.5, 4. ])
The variable idx contains the indices of the elements of w if they were inserted in v one by one. When inserting an array into another like above, only the value of idx corresponding to the minimum value of w will give as well the position of the same value into v.
Is there a way with numpy functions to obtain the indices of the elements of w once inserted?
wintov. A variableidx_newsuch thatv[idx_new] == wisTrueelement by element