2017-01-09 37 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)))