I have a numpy array of sample pairs (2-D) and an array of samples (1-D). I want to convert the sample pairs to a matching array (i.e. 2-D) representing the indices of the sample array. Is there a faster solution than what I have already employed?
import numpy as np
pair_list = np.array([['samp1', 'samp4'],
['samp2', 'samp7'],
['samp2', 'samp4']])
samples = np.array(['samp0', 'samp1', 'samp2', 'samp3', 'samp4', 'samp5',
'samp6', 'samp7', 'samp8', 'samp9'])
vfunc = np.vectorize(lambda s: np.where(samples == s)[0])
pair_indices = vfunc(pair_list)
In [180]: print(pair_indices)
[[1 4]
[2 7]
[2 4]]