WhatAMesh
WhatAMesh

Reputation: 174

Multiplying multidimensional matrices in tensorflow

When im trying to use tf.matmul to multiply a two Matrices with the shapes [41,22,512] & [512] I get the following Error:

ValueError: Shape must be rank 2 but is rank 3 for 'MatMul' (op: 'MatMul') 
with input shapes: [41,22,512], [512]..

I'd normally think that such a multiplication outputs a tensor with shape [41,22,1] or [41,22].

Upvotes: 0

Views: 299

Answers (1)

Vijay Mariappan
Vijay Mariappan

Reputation: 17201

Matmul wont work as the inner dimensions are not valid matrix multiplication arguments, instead you can do:

tf.reduce_sum(x * y, axis=2)

Upvotes: 1

Related Questions