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

浪尽此生 提交于 2020-03-24 08:21:31

3 月,跳不动了?>>>

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

 

发布了230 篇原创文章 · 获赞 192 · 访问量 60万+
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!