例如,
# Batch = 5, a = 25, b = 2
# tensor t1 shape: (Batch, a, b)
# tensor t2 shape: (Batch, b)
# tensor res shape: (Batch, a)
print(t1)
<tf.Tensor: id=466, shape=(2, 25, 2), dtype=int32, numpy=
array([[[ 1, 26],
[ 2, 27],
[ 3, 28],
[ 4, 29],
[ 5, 30],
[ 6, 31],
[ 7, 32],
[ 8, 33],
[ 9, 34],
[10, 35],
[11, 36],
[12, 37],
[13, 38],
[14, 39],
[15, 40],
[16, 41],
[17, 42],
[18, 43],
[19, 44],
[20, 45],
[21, 46],
[22, 47],
[23, 48],
[24, 49],
[25, 50]],
[[ 1, 26],
[ 2, 27],
[ 3, 28],
[ 4, 29],
[ 5, 30],
[ 6, 31],
[ 7, 32],
[ 8, 33],
[ 9, 34],
[10, 35],
[11, 36],
[12, 37],
[13, 38],
[14, 39],
[15, 40],
[16, 41],
[17, 42],
[18, 43],
[19, 44],
[20, 45],
[21, 46],
[22, 47],
[23, 48],
[24, 49],
[25, 50]]], dtype=int32)>
print(t2)
<tf.Tensor: id=410, shape=(2, 2), dtype=int32, numpy=
array([[1, 0],
[1, 0]], dtype=int32)>
# after matrix multiplication
print(res)
<tf.Tensor: id=474, shape=(2, 25), dtype=int32, numpy=
array([[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25],
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25]], dtype=int32)>
我认为的方式是使用矩阵乘法来只保留以前的部分,但我很难实现它。
如果不介意有人可以帮助我吗?