It is a method to extract other than a specific index from an array.
# 0~Randomly fetch 10 from the number 99
arr = np.random.randint(0, 100, 10)
# > array([74, 29, 6, 79, 76, 13, 3, 56, 25, 50])
#I want to exclude odd-numbered numbers from arr
odd = [1,3,5,7,9]
#Method ① List comprehension
index = [i for i in np.arange(len(arr)) if i not in odd]
arr_even = arr[index]
#Method ② True/Mask with False
index = np.ones(len(arr), dtype=bool)
index[odd] = False
arr_even = arr[index]
#Method ③ np.delete
arr_even = np.delete(arr, odd)
Method ③ is the most refreshing, but it doesn't change much in terms of time, so please use your favorite method.
Recommended Posts