np.dot() 和 np.matmul()

本文详细介绍了numpy库中用于向量和矩阵运算的两个关键函数:np.dot()和np.matmul()。np.dot()主要用于计算向量的内积和多维数组的矩阵乘法,其运算规则灵活,适用于不同形状的数组。而np.matmul()则遵循更严格的矩阵乘法规则,确保输入的最后维度匹配。通过实例解析,帮助读者深入理解这两个函数的使用方法和区别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

一、np.dot() : 向量的内积

举例

 二、np.matmul():矩阵乘法

举例 


一、np.dot() : 向量的内积

  • If a is an N-D array and b is a 1-D array, it is a sum product over the last axis of a and b.

  • If a is an N-D array and b is an M-D array (where M>=2), it is a sum product over the last axis of a and the second-to-last axis of b:

dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])

举例

 二、np.matmul():矩阵乘法

  • (n,k),(k,m)->(n,m)
  • the last dimension of x1 is the same size as the second-to-last dimension of x2

举例 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值