2017-01-09 103 views
0

我有一個文本文件的大小(20480,8)。我想把第四列中的數據放到一個數組中。我可以使用Python做它作爲使用張量流加載文本文件和訪問數據

file_pathname1 = os.path.join(os.path.expanduser('~'),'TF','1st_test', '20.10.22.12.09.13') 
x= np.loadtext(file_pathname1) 
y= x[:,4] 
#print(np.shape(x)) 
print(np.shape(y)) 

我得到y的尺寸爲(20480)

,但我想同樣的複製爲張量。如何訪問數據

file_pathname1 = os.path.join(os.path.expanduser('~'),'TF','1st_test', '20.10.22.12.09.13') 
y = tf.read_file(file_pathname1) 
sess = tf.Session() 
sess.run(y) 
print(y.get_shape()) 

我無法理解我是否已經加載正確的,因爲我得到它爲空數組文件 ()

回答

1

找到解決方案發布,如果它可以幫助別人

x1 = tf.constant(y,name = 'x1') 
model = tf.initialize_all_variables() 
with tf.Session() as session: 
    session.run(model) 
print(np.shape(session.run(x1)))