Playergod
Playergod

Reputation: 119

What does tf.keras.backend.dot does?

I am currently trying to implement LSTM in C. Therefore I need to understand https://www.tensorflow.org/api_docs/python/tf/keras/backend/dot.

For example if I would call: dot([1,2],[3,4,5])

for(i = 0; i<size1; i++)
{
    for(j = 0; j<size2; j++)
    {
        tmp += first[j]*second[i];
    }
    result[i] = tmp;
    tmp = 0;
}

So it would result: [1*3+2*3,1*4+2*4, 1*5+2*5]
Is this right?

Upvotes: 1

Views: 2272

Answers (1)

Ashwin Geet D&#39;Sa
Ashwin Geet D&#39;Sa

Reputation: 7379

Yes, it returns the dot product of the two tensors. And as per your example, it is right in the sense of dot product of variable length tensor, which is the same as matrix multiplication. Hence, you get it as expected.

Mathematically dot product of two variable a and b can be defined as: a.b=sum(a<i>*b<i>); where i ranges from 0 to n;

Upvotes: 1

Related Questions