1.数组转tensor:数组a, tensor_a=tf.convert_to_tensor(a) # 2.tensor转数组:tensor b, array_b=b.eval()
import tensorflow as tf import numpy as np a=np.array([[1,2,3],[4,5,6],[7,8,9]]) b=tf.convert_to_tensor(a) print(a)
>>>>>
[[1 2 3]
[4 5 6]
[7 8 9]]
print(b)
>>>>>
Tensor("Const:0", shape=(3, 3), dtype=int32)