import tensorflow as tf
import numpy as np
a=np.array([[1,2,3],[4,5,6],[7,8,9]])
print (a)
# [[1 2 3]
# [4 5 6]
# [7 8 9]]
b=tf.constant(a) #将array a 转换为tensor
tensor_a=tf.convert_to_tensor(a) #将array a 转换为tensor
print(b) #Tensor("Const:0", shape=(3, 3), dtype=int64)
with tf.Session() as sess:
print(b.eval()) #b.eval()就得到tensor的数组形式
# [[1 2 3]
# [4 5 6]
# [7 8 9]]
tensor_a=tf.convert_to_tensor(a) #将array a 转换为tensor
print ('现在转换为tensor了...',tensor_a)#现在转换为tensor了... Tensor("Const_1:0", shape=(3, 3), dtype=int64)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)