python中multiply函数_python中numpy库内multiply()、dot()和 * 三种乘法运算的区别小计...

首先,导入函数包:

import numpy as np

1.np.multiply()函数:

数组:(点对点)对应位置元素相乘

矩阵:对应位置元素相乘

示例:

A = np.array([[1,2],[3,4]])

B = np.array([[1,3],[2,4]])

A_mat = np.mat(A)

B_mat = np.mat(B)

A_B_multiply = np.multiply(A, B)

print(A_B_multiply)

'''

[[1,6],

[6,16]]

'''

A_B_mat_multiply = np.multiply(A.mat, B.mat)

print(A_B_mat_multiply)

'''

[[1,6],

[6,16]]

'''

2.np.dot()函数:

数组:(矩阵乘法)行对列,对应元素乘积后相加求和

矩阵:行对列,对应元素乘积后相加求和

示例:

A = np.array([[1,2],[3,4]])

B = np.array([[1,3],[2,4]])

A_mat = np.mat(A)

B_mat = np.mat(B)

A_B_dot = np.dot(A, B)

print(A_B_dot)

'''

[[5,11],

[11,25]]

'''

A_B_mat_dot = dot(A.mat, B.mat)

print(A_B_mat_dot)

'''

[[5,11],

[11,25]]

'''

3.* :

数组:对应位置元素相乘

矩阵:行对列,对应元素乘积后相加求和

示例:

A = np.array([[1,2],[3,4]])

B = np.array([[1,3],[2,4]])

A_mat = np.mat(A)

B_mat = np.mat(B)

print(A*B)

'''

[[1,6],

[6,16]]

'''

pritn((np.mat(A))*(np.mat(B)))

'''

[[5,11],

[11,25]]

'''

总结:

数组

矩阵

np.multiply()

点对点相乘

点对点相乘

np.dot()

矩阵乘法

矩阵乘法

*

点对点相乘

矩阵乘法

标签:mat,python,矩阵,np,multiply,array,numpy,dot

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值