# NumPy Product

## In this tutorial you will learn:

• What is the product of numbers?
• Implementation of product using different functions in Python
• Python Syntax

## Product of Number

Product is just another name for the operation of multiplication. It is a very common operation in the world of computation, mathematics and science. Product is taken of more than one elements which are contained in data structures like list, tuple, array etc

## Implementation of Product

Function prod() is used to get the product of all the elements of the array, the function takes in an array as an only mandatory parameter and returns a number as output. The result of this example will be 1644 (4 x 8 x 12 x 16)

`#importing the NumPy libraryimport numpy as np#declaring an arraymy_arr= np.array([4,8,12,16])print('Array of which product is being taken:', my_arr)#finding the product of contents of an arrayres = np.prod(my_arr)#printing the resultprint('The result of prod() function:', res)`

The prod() function can return the result of each array separately if we define its parameter “axis” equal to one. Here we will be taking three arrays and will find the prod of three arrays separately.
`#importing the NumPy libraryimport numpy as np#declaring three arraysmy_arr1= np.array([1,3,5,7])my_arr2=np.array([2,4,6,8])my_arr3=np.array([3,6,9,12])print('Three Arrays of which product is being taken:', my_arr1, my_arr2, my_arr3)#finding the product of contents of 3 arrays separatelyres = np.prod([my_arr1,my_arr2, my_arr3], axis=1)#printing the resultprint('The result of prod() function with axis = 1:', res)`

NumPy provides another function ‘cumprod()’, the function takes in an array and at each index gives out a cumulative product after multiplying up all the elements of the lower indexes of the array.
`#importing the NumPy libraryimport numpy as np#declaring an arrayarr= np.array([10,20,30,40])print('Array of which cummulative product is being taken:', arr)#taking the cummulative product of the contents of an arrayres = np.cumprod(arr)#printing the resultprint('The result of cumprod() function:', res)`

### Tags

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.