9951 explained code solutions for 126 technologies


python-numpyGet product of array elements over specific axis


import numpy as np 

a = np.array([[1,2], [3,4]])

prod_x = np.prod(a, axis=0)
prod_y = np.prod(a, axis=1)ctrl + c
import numpy as np

load Numpy module for Python

np.array

declare Numpy array

.prod(

returns product of elements of specified array

axis=

specify axis to calculate products over

prod_x

will contain array or vertical products

prod_y

will contain array of horizontal products