2017-01-23 21 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