Python | Numpy numpy.ndarray .__ mul __ ()

NumPy | Python Methods and Functions

With Numpy numpy.ndarray .__ mul __ () we can multiply a specific value provided as a parameter in ndarray .__ mul __ () ... The value will be multiplied by each array element .

Syntax: ndarray .__ mul __ ($ self, value, /)

Return: self * value

Example # 1:
In this example, we see that each element in array is multiplied by the value specified as a parameter in the ndarray .__ mul __ () method. This method will work well for positive, negative and floating point array values.

# import important module into python

import numpy as np

 
# make an array with NumPy

gfg = np.array ([ 1 , 2.5 , 3 , 4.8 , 5 ])

 
# applying the ndarray method .__ mul __ ()

print (gfg .__ mul __ ( 5 ))

Output:

 [5. 12.5 15. 24. 25.] 

Example # 2:

# import important module in python

import numpy as np

 
# make an array with NumPy

gfg = np.array ([[ 1 , 2 , 3 , 4.45 , 5 ],

[ 6 , 5.5 , 4 , 3 , 2.62 ]])

 
# applying the ndarray method .__ mul __ ()

print (gfg .__ mul __ ( 5 ))

Exit:

 [[5. 10. 15. 22.25 25.] [30. 27.5 20 . 15. 13.1]] 




Get Solution for free from DataCamp guru