为了账号安全,请及时绑定邮箱和手机立即绑定

np.dot() 和 np.multiply 的区别

np.dot() 和 np.multiply 的区别

萧十郎 2021-08-17 10:17:11
我正在将我的 matlab 功能转换为 python。我想用python重写这个简单的函数function [ H ] = update_H( X , W , H )     H = H.*((W'*X)./secu_plus(W'*W*H,eps));endfunction [ W ] = update_W( X , W , H )     W = W.*((X*H')./secu_plus(W*(H*H'),eps));end注意:secu_plus是另一个函数所以忽略。正如你所看到的,有两种乘法*和.*,我也有./那么python中的等价形式是什么 [(.* )  (./ ) and (*) ]
查看完整描述

2 回答

?
慕尼黑8549860

TA贡献1818条经验 获得超11个赞

Matlap 中,。operation表示元素明智的操作,例如如果 array1 = [ 1,2,3] 和 array3 [1,2,1],.*则将是 [1,4,3] Python numpy 中的 this 等价物 是np.multiply

np.dot 是两个向量之间的点积,点积在数学上是两个向量的乘积乘以中间夹角的余弦值,在二维坐标中相当于X1 * X2 + Y1 * Y2 作为一般形式AB = 总和 ai*bi

所以只需使用np.multiply()相当于.*


查看完整回答
反对 回复 2021-08-17
?
千巷猫影

TA贡献1829条经验 获得超7个赞

在 np.multiply() 中,两个数组的列数应该相同:


l = np.array([[1,2],[4,5],[7,8]])

a = np.array([[2,3]]

np.multiply(l,a)

output:

array([[ 8],

       [23],

       [38]])

其中 np.dot() 第一个矩阵中的列数=第二个矩阵中的行数


l = np.array([[1,2],[4,5],[7,8]])

a = np.array([[2,3]]).reshape(2,1)

np.dot(l,a)

output

array([[ 2,  6],

       [ 8, 15],

       [14, 24]])



查看完整回答
反对 回复 2021-08-17
  • 2 回答
  • 0 关注
  • 256 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信