Answers for "python sum over specific indexes"

0

python sum over specific indexes

# You can use sum directly after indexing with indices:
a = np.array([1,2,3,4])
indices = [0, 2] 
a[indices].sum()
# Result: 4
Posted by: Guest on August-20-2021

Python Answers by Framework

Browse Popular Code Answers by Language