tf.convert_to_tensor()函数的使用 | 数据类型转换

#将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)

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.EagerTensor'> tf.Tensor([1 2 3], shape=(3,), dtype=int32)
<class 'tensorflow.python.framework.ops.EagerTensor'> tf.Tensor([1 2 3], shape=(3,), dtype=int32)

 

上一篇:034 goodcopy


下一篇:spacy无法导入“en_core_web_sm”