0

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].

WhatAMesh
  • 153
  • 2
  • 13
  • Possible duplicate of [Tensorflow : ValueError: Shape must be rank 2 but is rank 3](https://stackoverflow.com/questions/42621652/tensorflow-valueerror-shape-must-be-rank-2-but-is-rank-3) – mdolata May 22 '18 at 12:43

1 Answers1

1

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

tf.reduce_sum(x * y, axis=2)
Vijay Mariappan
  • 16,921
  • 3
  • 40
  • 59