# Get the first element in the output layer

Dear All
I try to perform a simple multiplication using the first element of the output layer. My code looks like the following:
from tensorflow.keras.layers import *
import tensorflow as tf
scale_, mean_ = 2., 4.
a = Input(shape=(128,128), name=‘Input_vec’)
m_num = Input(shape=(4,), name=‘Input_num’)
output = Lambda(lambda x: tf.multiply(x, x))((a, m_num))

But I get the following error:
`ValueError: Dimensions must be equal, but are 128 and 4 for '{{node lambda_18/Mul}} = Mul[T=DT_FLOAT](Placeholder, Placeholder_1)' with input shapes: [?,128,128], .`

1 Like

Check `tf.multply` doc

If `x.shape` is not the same as `y.shape`, they will be broadcast to a compatible shape.

https://www.tensorflow.org/api_docs/python/tf/math/multiply#for_example

1 Like

@mohammad_gharaee , The shape of `a` in your code snippet would be `[None, 128, 128]` and shape of `m_num` would be `[None, 4]`.

IMO, I don’t think they are multiplication compatible. I mean you can still multiply by broadcasting as @Bhack mentioned above but it doesn’t make sense to me in this case.

Can you mention a specific use case that you are trying to achieve here. May be then someone can help.

1 Like

thanks @ashutosh1919, @Bhack

Actually here is my idea. I try to get some some parameters from image and using them create a matrix for next layer. In the image below you may see my rough idea. So I want to multiply each set of params to image.

2 Likes

@mohammad_gharaee , I think you forgot to attach the image.

1 Like

I tried to do so but I got the error “Sorry, you can’t embed media items in a post.”

1 Like

@ashutosh1919

Here is the image. Just replace - with .