# TensorDot and axis reduction

I have 2 tensors a and blike [?,200,200,48] and i want to get the dot product on axis 4 to obtain a tensor like [?,200,200,1].

I tried to use tf.tensordot(a,b,axis=[[3][3]]) and the result is tensor like [?,200,200,?,200,200]

Try this:

from tensorflow.keras.layers import *
import tensorflow.keras.backend as K
import tensorflow as tf

BS = 100
x = K.random_normal((BS, 200, 200, 48))
y = K.random_normal((BS, 200, 200, 48))

K.sum(tf.multiply(x, y[:tf.newaxis]), axis=-1, keepdims=True).shape


Detailed explanation from here: https://stackoverflow.com/questions/51657476/keras-dot-dot-layer-behavior-on-3d-tensors

• Thank you, it works perfectly! – bob87 Jul 15 at 14:41