Numpy np.乘以vs *-运算符 [英] Numpy np.multiply vs *-Operator

查看:33
本文介绍了Numpy np.乘以vs *-运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用上有什么区别

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆