设A为[d1,d2,…dn,m,p]的张量,B为[d1,d2,…dn,p,n] 的张量,那么称[d1,d2,…dn,m,n]的张量C为张量A与B的叉乘。也就是说,执行叉乘运算的2个张量需要在最后的2个维度上满足[m,p]和[p,n]这样的形状。而且其余的维度也要匹配。
举例如下:
import tensorflow as tf
a=range(72)
b=tf.reshape(a,[3,2,3,4])
b=tf.cast(b,dtype=tf.float32)
c=tf.reshape(b,[3,2,4,3])
print(tf.matmul(b,c))
print(b@c)