# Concatenate two tensors of different shape

I have two tensors:

a.shape = (1, 30, 1220) # represents text embedding vector (30 spans, each with embedding size of 1220)
b.shape = (1, 128, 256) # represents image features obtained from a pretrained CNN

1. How do I concatenate everything in b to each one of the 30 spans of a?

2. How to concatenate the whole b to the whole a?

You can't concatenate these two arrays, because their shapes don't match. You could concatenate them if you had:

1)

    a.shape = (1, 30, 1220)
b.shape = (1, 30, 256)

    a.shape = (1, 30, 1220)
b.shape = (1, 128, 1220)


or eventually

3)

    a.shape = (1, 30, 1220)
b.shape = (1, 128, 30)

    a.shape = (1, 30, 1220)
b.shape = (1, 1220, 256)

• Can I flatten the image feature vector and then concatenate with text feature vector?
– Sid
Sep 3 at 1:01