tf.convert_to_tensor的用法

来源:互联网 发布:淘宝卖蚕丝被 编辑:程序博客网 时间:2024/05/16 15:38
tf.convert_to_tensor用于将不同数据变成张量:比如可以让数组变成张量、也可以让列表变成张量。
例如:
import tensorflow as tf;import numpy as np;A = list([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)print type(B)print type(C)print type(D)

输出:
<type 'list'><type 'numpy.ndarray'><class 'tensorflow.python.framework.ops.Tensor'><class 'tensorflow.python.framework.ops.Tensor'>
原创粉丝点击