📜  Python| numpy numpy.ndarray.__imul__()

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

Python| numpy numpy.ndarray.__imul__()

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

示例 #1:
在这个例子中,我们可以看到数组中的每个元素都与 ndarray.__imul__() 方法中作为参数给出的值相乘。请记住,此方法适用于每种类型的数值。

Python3
# import the important module in python
import numpy as np
   
# make an array with numpy
gfg = np.array([1.2, 2.6, 3, 4.5, 5])
   
# applying ndarray.__imul__() method
print(gfg.__imul__(5))


Python3
# import the important module in python
import numpy as np
   
# make an array with numpy
gfg = np.array([[1, 2.2, 3, 4, 5.01],
                [6.1, 5, 4.8, 3, 2]])
   
# applying ndarray.__imul__() method
print(gfg.__imul__(3))


输出:
[  6.   13.   15.   22.5  25. ]

示例 #2:

Python3

# import the important module in python
import numpy as np
   
# make an array with numpy
gfg = np.array([[1, 2.2, 3, 4, 5.01],
                [6.1, 5, 4.8, 3, 2]])
   
# applying ndarray.__imul__() method
print(gfg.__imul__(3))
输出:
[[  3.     6.6    9.    12.    15.03]
 [ 18.3   15.    14.4    9.     6.  ]]