Product of all Element in Numpy Array by R4R Team

- product() is a Python Numpy method that multiple all number in the array and return product.
- valid only on integer array.

Syntax-

p=numpy.product(array)

Example-
array is [1,2,3]
product is 6

array is
[[1,2]
[2,3]]
product is 12


program-

#import numpy
import numpy as np

l=[1,2,3,4]
arr=np.array(l)
print("Array isn",arr)
print("Product is :",np.product(arr))

l=[[1,2,3],[3,2,1],[1,1,1]]
arr=np.array(l)
print("nArray isn",arr)
print("Product is :",np.product(arr))

l=[[1,2,3],[3,2,1],[1,0,1]]
arr=np.array(l)
print("nArray isn",arr)
print("Product is :",np.product(arr))


output-

Array is
[1 2 3 4]
Product is : 24

Array is
[[1 2 3]
[3 2 1]
[1 1 1]]
Product is : 36

Array is
[[1 2 3]
[3 2 1]
[1 0 1]]
Product is : 0

-In this program, we have a three list that convert into the Numpy array then we find the product of the number in array.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!