tensorflow中tensor与数组之间的转换
# 主要是两个方法: # 1.数组转tensor:数组a, tensor_a=tf.convert_to_tensor(a) # 2.tensor转数组:tensor b, array_b=b.eval()
1 import tensorflow as tf 2 import numpy as np 3 4 a=np.array([[1,2,3],[4,5,6],[7,8,9]]) 5 print (a) 6 b=tf.constant(a) 7 8 with tf.Session() as sess: 9 print (b) 10 for x in b.eval(): #b.eval()就得到tensor的数组形式 11 print (x) 12 13 print ('a是数组',a) 14 15 tensor_a=tf.convert_to_tensor(a) 16 print ('现在转换为tensor了...',tensor_a)