2017-01-23 73 views
0

我有一个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]将变量“池”和我期待的变量poolfinal的大小[5x13],但我把它作为[1x13]。 如何在垂直方向进行连接? 我在循环中犯的错误是什么?

回答

0

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

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

当我使用pool.append我不用再在到poolfinal,我想复制这样做使用tensorflow功能concat_v2 – Raady