You can do it like this.
itemgetter_iterable_example.py
import numpy as np
from operator import itemgetter
np_list = np.linspace(0, 1, num=11)
# -> array([ 0. ,  0.1,  0.2,  0.3,  0.4,  0.5,  0.6,  0.7,  0.8,  0.9,  1. ])
py_list = list(np_list)
indexes = [1, 3, 5]  #Appropriate index
#With NumPy it looks like this
np_list[indexes]
# -> array([ 0.1,  0.3,  0.5])
#A Python list looks like this
itemgetter(*indexes)(py_list)
# -> (0.1, 0.3, 0.5)
There is also a story that you only have to convert it to NumPy once.
Recommended Posts