Python 如何在tensorflow中增加数组的多维度?

Python 如何在tensorflow中增加数组的多维度?,python,arrays,multidimensional-array,tensorflow,concat,Python,Arrays,Multidimensional Array,Tensorflow,Concat,我有一个txt文件,它有8列,我正在为我的特征提取选择1列,这给了我13个特征值,输出数组的形状将是[1x13]。 类似地,我在一个文件夹中有5个txt文件,我想运行一个循环,以便返回的变量将有5x13数据 def loadinfofromfile(directory,sd,channel): # subdir selection and read file names in it for particular crack type. subdir, filenames = lo

我有一个txt文件,它有8列,我正在为我的特征提取选择1列,这给了我13个特征值,输出数组的形状将是[1x13]。 类似地,我在一个文件夹中有5个txt文件,我想运行一个循环,以便返回的变量将有5x13数据

def loadinfofromfile(directory,sd,channel):
    # subdir selection and read file names in it for particular crack type.
    subdir, filenames = loadfilenamesindirectory(directory,sd)
    for i in range(5):
        # join the directory sub directory and the filename
        loadfile = os.path.join(directory,subdir,filenames[i])
        # load the values of that paticular file into tensor
        fileinfo = tf.constant(np.loadtxt(loadfile),tf.float32)
        # select the particular column data ( choosen from crack type, channel no)
        fileinfo_trans = tf.transpose(fileinfo)
        fileinfo_back = tf.gather(fileinfo_trans,channel)
        # extracting features from selected column data gives [1x13]
        pool = features.pooldata(fileinfo_back)
        poolfinal = tf.concat_v2([tf.expand_dims(pool,0)],axis=0)
    return poolfinal
在上面的函数中,我可以将[1x13]获取到变量“pool”,我希望变量poolfinal的大小为[5x13],但我将其获取为[1x13]。 如何在垂直方向下切?
我在循环中犯了什么错误?

每个循环都从策略创建pool和poolfinal。这就是为什么在poolfinal中只能看到一个数据。 请尝试以下操作:

pools = []
for ...:
  pools.append(...)
poolfinal = tf.concat_v2(pools, axis=0)

当我使用pool.append时,我不需要再次将它复制到poolfinal中,我想使用tensorflow函数concat_v2来完成