I want to merge two CNN deep learning model using Keras and would like to know what is the difference multiply and dot functions that is used to merge layer?


keras.layers.dot(inputs, axes, normalize=False)

1 Answer 1


The multiply() function performs element-wise multiplication. For example, let us consider 1D CNN for simplicity and you pass two inputs of batch size b with a tensor length of 5, the output will be (b,5) as it's element-wise multiplication. Let us assume two tensors of length 5 as follows: [1,2,3,4,5] and [6,7,8,9,10], the result shall be [6,14,24,36,50] as it's just element-wise multiplication.

In the case of dot(), it takes the dot product, and the dot product for 1D is mathematically defined as: a.b = sum(a_i * b_i), where i ranges from 0 to n-1; where n is the number of elements in vector a and b. (For 2-D , you can consider it as matrix multiplication). So the result shall be of length (b,1) where b is the batch size. In case of out example, the results of dot product of [1,2,3,4,5] and [6,7,8,9,10] shall be [130]


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.