Search
 
SCRIPT & CODE EXAMPLE
 

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]]
Comment

PREVIOUS NEXT
Code Example
Python :: kaggle replace 
Python :: data framing with Pandas 
Python :: Python NumPy asarray Function Example list to array 
Python :: Python NumPy asfortranarray Function Syntax 
Python :: Python NumPy asarray_chkfinite Function Example Tuple to an array 
Python :: Python NumPy block Function Example by using simple array 
Python :: Python NumPy row_stack Function Example with 2d array 
Python :: percentile of a score python 
Python :: How can I Duplicate 1 Dimensional array 
Python :: creating a variable bound to a set python 
Python :: pandas dt.weekday to string 
Python :: __ne__ 
Python :: NumPy bitwise_and Example When inputs are numbers 
Python :: how to split a string every 2 characters python 
Python :: NumPy right_shift Syntax 
Python :: tikzplotlib set figure 
Python :: # find all text files in directory or any type of files in directory 
Python :: python list and numpy array 
Python :: Double all numbers using a map() Function 
Python :: ccacxc 
Python :: parsing output from ping - python 
Python :: operasi tipe data integer 
Python :: how to end if else statement in python 
Python :: HTML not being displayed properly in Flask, Python 
Python :: python while loop command gaming code 
Python :: python request.args.get list 
Python :: ring raise an exception 
Python :: pandas rolling list 
Python :: pairplot seaborn legend best position set 
Python :: df.write using another delimiter 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =