Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to concat two tensors different shape

I have two tensors, get_shape = [?, 400] and [?, 1176]. I want to concat them into one tensor of size [?, 1576].

I tried concat, but it requires both to be the same dimension.

How to do so?

like image 292
Abdallah Nasir Avatar asked Oct 17 '22 02:10

Abdallah Nasir


1 Answers

Hopefully, you are passing same dimension of input via batch size.

import tensorflow as tf
import numpy as np

t1 = tf.placeholder(tf.float32, [None, 400])
t2 = tf.placeholder(tf.float32, [None, 1176])
t3 = tf.concat([t1, t2], axis = 1)

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    t3_val = sess.run(t3, feed_dict = {t1: np.ones((300, 400)), t2: np.ones((300, 1176))})

    print(t3_val.shape)
    # (300, 1576)
like image 57
Prasad Avatar answered Oct 21 '22 04:10

Prasad