Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python sum certain postions of array


a = np.array([1,2,3,4])   # numpy array with 4 positions
indices = [0, 2]          # list of the indices to sum.

a[indices].sum()		  # returns a[0] + a[2]
Comment

PREVIOUS NEXT
Code Example
Python :: get the first element that is larger than 
Python :: hide verbose in pip install 
Python :: Python __floordiv__ 
Python :: Returns a DataFrame representing the result of the given query 
Python :: python append to a exiting csv file 
Python :: dependency inversion 
Python :: pandas and operator 
Python :: keras embedding 
Python :: flask sqlalchemy case insensitive like 
Python :: pyqt popup yes no 
Python :: pyqt5 spin box change value trigger 
Python :: python requests cannot find existing url 
Python :: python logging change handler level 
Python :: retrieve content inside the meta tag python 
Python :: stripping whitespace in python 
Python :: remove SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame 
Python :: webdriver.chrome() python not working 
Python :: histogram relative frequency 
Python :: how to use with statementin python 2.4 
Python :: Range all columns of df such that the minimum value in each column is 0 and max is 1. in pandas 
Python :: numpy random entries not repeat 
Python :: mathtext to regular python 
Python :: how can I print all items in a tuple, separated by commas? 
Python :: get script text selenium python 
Python :: stdin and stdout python 
Python :: install pytorch on nvidia jetson nx 
Python :: python popen 
Python :: python last non-zero value in a list 
Python :: minio python create bucket 
Python :: toolbar pyqt 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =