title: "InvalidArgumentError: Incompatible shapes: [64,40000] vs. [64] [Op:Mul]" while doing operations between tensors?
body: <p>I'm trying to do this operation between two tensors:</p>
  <pre><code>green_mat = sio.loadmat('green.mat')
  green = np.array(green_mat['G2'])
  green = tf.convert_to_tensor(green)
  green = tf.cast(green, dtype='complex64')  # &gt;&gt;&gt;green.shape = TensorShape([64, 40000])
  
  
  
  tensor = tf.ones(128,1)        # tensor.shape = TensorShape([128])
  
  def mul_and_sum(tensor):
     real = tensor[0:64]
     imag = tensor[64:128]
     complex_tensor = tf.complex(real, imag)
     return tf.reduce_sum((tf.multiply(green, complex_tensor), 1))
  
  res = mul_and_sum(tensor)
  </code></pre>
  <p>basically, at the end what I want to obtain is a tensor with 40000 elements to use as a layer for a neural network, but when I run this function as a test I have this error:</p>
  <pre><code>tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [64,40000] vs. [64] [Op:Mul]
  </code></pre>
  <p>It's the first time I'm working on tensors operation and maybe I'm a bit confused on how to treat the dimensions, any suggestions? Thanks :)</p>
  <p><strong>EDIT</strong>: ok, I have understood the point, indeed for the example that I provided everything works, but then I have another problem in my network:</p>
  <pre><code>def convolution(tensor):
  tf.cast(tensor, dtype='float64')
  real = tensor[0:64]
  imag = tensor[64:128]
  complex_tensor = tf.complex(real, imag)
  a = tf.math.real(tf.reduce_sum((tf.multiply(green, complex_tensor)), 0))
  return a
  
  def get_model3(mask_kind):
  epochs = 200
  learning_rate = 0.1
  decay_rate = learning_rate / epochs
  inp_1 = keras.Input(shape=(64, 101, 129), name=&quot;RST_inputs&quot;)
  x = layers.Conv2D(1, kernel_size=(1, 1), strides=(1, 1), padding=&quot;valid&quot;, trainable=False)(inp_1)
  x = layers.Conv2D(256, kernel_size=(3, 3), kernel_regularizer=l2(1e-6), strides=(3, 3), padding=&quot;same&quot;)(x)
  x = layers.LeakyReLU(alpha=0.3)(x)
  x = layers.Conv2D(128, kernel_size=(3, 3), kernel_regularizer=l2(1e-6), strides=(3, 3), padding=&quot;same&quot;)(x)
  x = layers.LeakyReLU(alpha=0.3)(x)
  x = layers.Conv2D(64, kernel_size=(2, 2), kernel_regularizer=l2(1e-6), strides=(2, 2), padding=&quot;same&quot;)(x)
  x = layers.LeakyReLU(alpha=0.3)(x)
  x = layers.Conv2D(32, kernel_size=(2, 2), kernel_regularizer=l2(1e-6), strides=(2, 2), padding=&quot;same&quot;)(x)
  x = layers.LeakyReLU(alpha=0.3)(x)
  x = layers.Flatten()(x)
  x = layers.Dense(512)(x)
  x = layers.LeakyReLU(alpha=0.3)(x)
  x = layers.Dense(256)(x)
  x = layers.LeakyReLU(alpha=0.3)(x)
  out1 = layers.Dense(128, name=&quot;ls_weights&quot;)(x)
  
  if mask_kind == 1:
      binary_mask = layers.Lambda(mask_layer1, name=&quot;lambda_layer&quot;, dtype='float64')(out1)
  elif mask_kind == 2:
      binary_mask = layers.Lambda(mask_layer2, name=&quot;lambda_layer&quot;, dtype='float64')(out1)
  else:
      binary_mask = out1
  #here the binary mask shape is [?,128]
  binary_mask = tf.expand_dims(binary_mask, axis=2)  #here the shape is [?,128,1]
  binary_mask = tf.squeeze(binary_mask, axis=0) #here the shape is [128,1]
  
  print('binary shape:', binary_mask.shape)
  
  lambda_layer = layers.Lambda(convolution, name=&quot;convolutional_layer&quot;)(binary_mask)
  print(lambda_layer.shape)
  
  
  model3 = keras.Model(inp_1,  lambda_layer, name=&quot;2_out_model&quot;)
  
  model3.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=decay_rate),  # in caso
                 # rimettere 0.001
                 loss=&quot;mean_squared_error&quot;)
  
  plot_model(model3, to_file='model.png', show_shapes=True, show_layer_names=True)
  model3.summary()
  
  return model3
  </code></pre>
  <p>and I get this error:</p>
  <pre><code>ValueError: Input 0 of layer sf_vec is incompatible with the layer: : expected min_ndim=2, found ndim=1. Full shape received: [40000]
  </code></pre>
  <p>I know that it is because there is a mismatch between the dimension, but the fact is that the shape of the output layer(tensor) should be [?,40000] and instead I get only a tensor of [40000], any suggestion?</p>
  <p><strong>EDIT 2.0</strong> I didn't noticed that my output was already the lambda layer so in the way the model is written I get no errors, but from the summary in this way I get as lambda shape (1, 40000)  while usually should be (None,40000).
  Where is the error?</p>