Numpy np.乘以vs *-运算符 [英] Numpy np.multiply vs *-Operator
问题描述
使用上有什么区别
import numpy as np
a, b = np.random([1024, 1024]), np.random([1024, 1024])
c = np.multiply(a, b)
在
c = a * b
还是numpy数组上的*
-运算符只是被np.multiply
覆盖?
or is the *
-Operator on numpy-arrays simply overridden with np.multiply
?
编辑 :此问题被标记为重复,因为使查找更加容易答案,我主张将这个问题保持原样.
Edit: This question is marked as duplicate because a question asks the same thing about the division operator (np.divide()
vs /
) and similar answers followed, but unless it is changed to "numpy arithmetic vs. python arithmetic" or something of the kind, it won't help people wondering the same thing as I did (about multiplication) and not being "clever" enough to assume a question about a related arithmetic operation (division) generalizes to all the basic arithmetic operations. To make it easier finding answers, I'd advocate for keeping this question as is.
推荐答案
没有区别.但是,np.multiply
函数可以接受其他可选参数,从而使其更具通用性.请参见文档.
There is no difference. However, the np.multiply
function can take in additional, optional arguments, making it more versatile. See the docs.
说*
被np.multiply
覆盖并不十分精确.通常,*
映射到对其作用的对象上对__mul__
和__rmul__
方法的调用.因此,*
被np.ndarray.__mul__
所覆盖".
Saying that *
is overwritten with np.multiply
would not be very precise. Generally, *
maps to calls to the __mul__
and __rmul__
methods on the objects on which it acts. Thus, *
is rather "overwritten" with np.ndarray.__mul__
.
这篇关于Numpy np.乘以vs *-运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!