Tensorflow 如何计算N张量?N在运行时决定

Tensorflow 如何计算N张量?N在运行时决定,tensorflow,Tensorflow,我想做什么 M = tf.concat([tensor]*N, axix = 0) 但现在,N是一个在运行时决定的张量 other_tensor = tf.placeholder(dtype=tf.int32, shape=[None, 2]) N = tf.shape(other_tensor)[0] # N is None, and it is decided in run time. 那么,如何做到这一点呢?您应该使用,而不是concat。要获得形状,请使用以下示例: import

我想做什么

M = tf.concat([tensor]*N, axix = 0) 
但现在,N是一个在运行时决定的张量

other_tensor = tf.placeholder(dtype=tf.int32, shape=[None, 2])
N = tf.shape(other_tensor)[0] # N is None, and it is decided in run time.
那么,如何做到这一点呢?

您应该使用,而不是concat。要获得形状,请使用以下示例:

import tensorflow as tf

a = tf.constant([[1, 2], [3, 4]])
b = tf.constant([1, 2])
c = tf.tile(a, (1, int(a.get_shape()[0])))
with tf.Session() as sess:
    print sess.run(c)

如果您需要张量的形状稍有不同,请阅读tile函数中的第二个参数,并使用
tf。重塑

谢谢您的回答。也许我没说清楚。在我的情况下,a=tf.placeholder(dtype=tf.int32,shape=[None,2])@ZehaoShi看你前面的问题,答案是‘不,一点也不清楚’。要回答您的后续问题,请转到get_shape链接,查看在动态形状的情况下如何使用tf.shape()获取动态形状。tf.tile()正是我想要的。多谢各位。为了方便其他人,我现在重写这个问题。