简体   繁体   English

是否有用于计算矩阵列或向量列表中所有对之间的所有成对点积的函数?

[英]Is there a function for calculating all the pairwise dot products of the columns of a matrix, or between all pairs in a list of vectors?

Say you have n.说你有n。 vectors of arbitrary (but equal) length m each.任意(但相等)长度为 m 的向量。 Is there a (numpy?) function, or a quick way, of calculating all pairwise dot products between these n.是否有(numpy?)函数或快速方法来计算这些 n 之间的所有成对点积。 vectors?向量?

My initial thought was that you could calculate A T A and take the upper triangular portion, but I'm not sure if that matrix multiplication is slow/computationally intensive.我最初的想法是你可以计算 A T A 并取上三角部分,但我不确定矩阵乘法是否很慢/计算密集。 Is there a quicker/efficient way?有没有更快/有效的方法? Or should I just define a function using a for loop for all combinations of pairs?或者我应该只使用 for 循环为所有对组合定义一个函数?

As per @Brenila's comment, use tensordot :根据@Brenila 的评论,使用tensordot

np.tensordot(arr, arr, axes=(0,0))

Result shape is (n, n) for n = arr.shape[-1]对于n = arr.shape[-1] (n, n)结果形状为(n, n)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 计算所有列之间的成对相关性 - Calculating pairwise correlation among all columns 列表中所有对的乘积之和 - Sum of products of all pairs in a list 矩阵中自向量的点积 - Dot products of self vectors in a matrix 创建一个 function 以仅使用 numpy 计算二维矩阵中行向量的所有成对余弦相似度 - create a function to compute all pairwise cosine similarity of the row vectors in a 2-D matrix using only numpy 计算数据帧所有行之间的成对欧几里得距离 - Calculating pairwise Euclidean distance between all the rows of a dataframe numpy:将两个向量(或一个与它本身)的笛卡尔积相乘来创建矩阵,同时将函数应用于所有对 - Numpy: create a matrix from a cartesian product of two vectors (or one with itself) while applying a function to all pairs 在 Numpy 中的矩阵列表和向量列表之间应用矩阵点 - Apply matrix dot between a list of matrices and a list of vectors in Numpy PyTorch 中一组向量之间的成对相似度矩阵 - Pairwise similarity matrix between a set of vectors in PyTorch 计算列的范数作为矩阵中的向量 - Calculating norm of columns as vectors in a matrix 如何从所有 pandas 列计算成对矩阵 - How to compute pairwise matrix from all pandas columns
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM