#将python的数据类型(列表和矩阵)转换成TensorFlow可用的tensor数据类型
import tensorflow as tf
import numpy as np
A = [1,2,3]
B = np.array([1,2,3])
C = tf.convert_to_tensor(A)
D = tf.convert_to_tensor(B)
with tf.Session() as sess:
print(type(A), A)
print(type(B), B)
print(type(C), C)
print(type(D), D)
# 结果:
# <class 'list'> [1, 2, 3]
# <class 'numpy.ndarray'> [1 2 3]
# <class 'tensorflow.python.framework.ops.Tensor'> Tensor("Const_10:0", shape=(3,), dtype=int32)
# <class 'tensorflow.python.framework.ops.Tensor'> Tensor("Const_11:0", shape=(3,), dtype=int32)
tf.convert_to_tensor()函数的使用 | 数据类型转换
最新推荐文章于 2022-08-09 15:15:11 发布