Say you have n. vectors of arbitrary (but equal) length m each. Is there a (numpy?) function, or a quick way, of calculating all pairwise dot products between these 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. Is there a quicker/efficient way? Or should I just define a function using a for loop for all combinations of pairs?
As per @Brenila's comment, use tensordot :
np.tensordot(arr, arr, axes=(0,0))
Result shape is (n, n)
for n = arr.shape[-1]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.