Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to extract a list of values from numpy array using index list

import numpy as np

filter_indices = [1, 2]
array = np.array([[1, 2, 3, 4, 5], 
                  [10, 20, 30, 40, 50], 
                  [100, 200, 300, 400, 500]])

axis = 0
print(np.take(array, filter_indices, axis))
# [[ 10  20  30  40  50]
#  [100 200 300 400 500]]

axis = 1
print(np.take(array, filter_indices, axis))
# [[  2   3]
#  [ 20  30]
# [200 300]]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #extract #list #values #numpy #array #index #list
ADD COMMENT
Topic
Name
8+6 =