📜  Python| numpy numpy.ndarray.__mul__()

📅  最后修改于: 2022-05-13 01:55:33.832000             🧑  作者: Mango

Python| numpy numpy.ndarray.__mul__()

Numpy numpy.ndarray.__mul__()的帮助下,我们可以乘以在ndarray.__mul__()方法中作为参数提供的特定值。值将乘以numpy 数组中的每个元素。

示例 #1:
在这个例子中,我们可以看到数组中的每个元素都与ndarray.__mul__()方法中作为参数给出的值相乘。此方法适用于数组的正值、负值和浮点值。

# import the important module in python
import numpy as np
   
# make an array with numpy
gfg = np.array([1, 2.5, 3, 4.8, 5])
   
# applying ndarray.__mul__() method
print(gfg.__mul__(5))
输出:
[  5.   12.5  15.   24.   25. ]

示例 #2:

# import the 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 ndarray.__mul__() method
print(gfg.__mul__(5))
输出:
[[  5.    10.    15.    22.25  25.  ]
 [ 30.    27.5   20.    15.    13.1 ]]