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'>
本文介绍如何使用TensorFlow中的tf.convert_to_tensor函数将列表或NumPy数组转换为张量。通过示例代码展示了不同类型的数据结构如何被转换,并验证了转换后的数据类型。
501





