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)

 

posted @ 2022-02-26 11:30  图神经网络  阅读(609)  评论(0编辑  收藏  举报
Live2D