Numpy accumulate

import numpy as np

x = np.arange(5,11)

print(x)

y = np.add.accumulate(x)

print(‘Addition: ‘,y)


print()


x1 = np.arange(1,7)

print(x1)

y1=np.multiply.accumulate(x1)

print(‘Multiplication: ‘,y1)


Output

[ 5 6 7 8 9 10]
Addition: [ 5 11 18 26 35 45]

[1 2 3 4 5 6]
Multiplication: [ 1 2 6 24 120 720]

Published by Python programming examples for beginners

Abhay Gadkari is an IT professional having around experience of 20+ years in IT industry. He worked on web technologies and databases with Insurance and ERP projects.