点乘与矩阵乘积

文章展示了使用numpy库进行矩阵运算的各种情况,包括点积(dot)函数的应用,矩阵乘法以及转置的组合。通过不同的运算顺序,如np.dot(A@X,B@Y)和np.dot(X,Y@B@A),得出不同结果,强调了矩阵运算的顺序重要性。
摘要由CSDN通过智能技术生成
A=np.array([[1,2,3],[4,5,6],[7,8,9]])

B=np.array([[3,1,5],[9,2,4],[6,8,7]])

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

Y=np.array([7,0,2])

np.dot(A@X,B@Y)
Out[21]: 6446

np.dot(A@X,np.array([Y])@B.T)
Traceback (most recent call last):

  File "<ipython-input-22-5de65b47e121>", line 1, in <module>
    np.dot(A@X,np.array([Y])@B.T)

ValueError: shapes (3,) and (1,3) not aligned: 3 (dim 0) != 1 (dim 0)




np.dot(A@X,Y.T@B.T)
Out[23]: 6446

np.dot(A@X,Y.T@B)
Out[24]: 4269

np.dot(A@X,Y@B.T)
Out[25]: 6446

np.dot(X,Y@A@B.T)
Out[26]: 3006

np.dot(X,Y@A.T@B.T)
Out[27]: 3918

np.dot(X,Y@B.T@A.T)
Out[28]: 5098

np.dot(X,Y@B.T@A)
Out[29]: 6446

np.linalg.inv(A)
Out[30]: 
array([[ 3.15251974e+15, -6.30503948e+15,  3.15251974e+15],
       [-6.30503948e+15,  1.26100790e+16, -6.30503948e+15],
       [ 3.15251974e+15, -6.30503948e+15,  3.15251974e+15]])

np.dot(X,(A@B@Y))
Out[31]: 5098

np.dot(X,(A@B@Y).T)
Out[32]: 5098

Y@B.T@A.T
Out[33]: array([ 341,  815, 1289])

(A@B@Y).T
Out[34]: array([ 341,  815, 1289])

np.dot(X,Y@B.T@A)
Out[35]: 6446

np.dot(X,(A@B@Y).T)
Out[36]: 5098

Z1=(A@B@Y).T


np.dot(X,Z1)
Out[38]: 5098

Z2=Y@B.T@A.T

np.dot(X,Z2)
Out[40]: 5098

np.dot(X,Y@B.T@A)
Out[41]: 6446

np.dot(X,Y@B.T@A.T)
Out[42]: 5098

A=np.array([[1,2,3],[9,9,699],[7,8,9]])

np.dot(A@X,Y.T@B.T)
Out[44]: 57921

np.dot(X,Y@B.T@A)
Out[45]: 57921

np.dot(Y.T,B.T@A@X)
Out[46]: 57921

AX.* (BY)‘=AX.* Y’B’=X.*(Y’B’A)=Y’B’AX

这里的 ’ 表示矩阵的转置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值