TensorFlow 中的 'Tensor' 到底是什么?
What exactly qualifies as a 'Tensor' in TensorFlow?
我是 TensorFlow 的新手,刚刚学习了 eager execution 教程并遇到了 tf.decode_csv 函数。不知道,我阅读了文档。 https://www.tensorflow.org/api_docs/python/tf/decode_csv
我不是很懂。
文档说 'records: A Tensor of type string.'
所以,我的问题是:什么才算 'Tensor'?
我尝试了以下代码:
dec_res = tf.decode_csv('0.1,0.2,0.3', [[0.0], [0.0], [0.0]])
print(dec_res, type(dec_res))
l = [[1,2,3],[4,5,6],[7,8,9]]
r = tf.reshape(l, [9,-1])
print(l, type(l))
print(r, type(r))
因此列表 dec_res
包含 tf.tensor 个对象。这对我来说似乎是合理的。但是根据文档,普通字符串也是 'Tensor' 吗?
然后我用 tf.reshape
函数尝试了一些其他的东西。在文档 https://www.tensorflow.org/api_docs/python/tf/reshape 中它说 'tensor: A Tensor.' 所以,l
应该是一个张量。但它不是 tf.tensor
类型,而只是 python list
类型。这令人困惑。
然后文档说
Returns:
A Tensor. Has the same type as tensor.
但是 l
的类型是 list
而 r
的类型是 tensorflow.python.framework.ops.Tensor
。所以类型不一样。
然后我认为 TensorFlow 非常慷慨地将事物作为张量。所以我尝试了:
class car(object):
def __init__(self, color):
self.color = color
red_car = car('red')
#test_reshape = tf.reshape(red_car, [1, -1])
print(red_car.color) # to check, that red_car exists.
现在,注释中的行导致错误。
所以,谁能帮我找出什么才算 'Tensor'?
P.S.: 我试图阅读文档
中给出的 tf.reshape
的源代码
Defined in tensorflow/python/ops/gen_array_ops.py.
但是 Github 仓库中不存在这个文件。有人知道怎么读吗?
https://www.tensorflow.org/programmers_guide/tensors
TensorFlow, as the name indicates, is a framework to define and run
computations involving tensors. A tensor is a generalization of
vectors and matrices to potentially higher dimensions. Internally,
TensorFlow represents tensors as n-dimensional arrays of base
datatypes.
您所观察到的事实是,可以使用函数 tf.convert_to_tensor:
从各种 python 类型构建张量流操作(如重塑)
https://www.tensorflow.org/api_docs/python/tf/convert_to_tensor
All standard Python op constructors apply this function to each of
their Tensor-valued inputs, which allows those ops to accept numpy
arrays, Python lists, and scalars in addition to Tensor objects
我是 TensorFlow 的新手,刚刚学习了 eager execution 教程并遇到了 tf.decode_csv 函数。不知道,我阅读了文档。 https://www.tensorflow.org/api_docs/python/tf/decode_csv
我不是很懂。
文档说 'records: A Tensor of type string.' 所以,我的问题是:什么才算 'Tensor'?
我尝试了以下代码:
dec_res = tf.decode_csv('0.1,0.2,0.3', [[0.0], [0.0], [0.0]])
print(dec_res, type(dec_res))
l = [[1,2,3],[4,5,6],[7,8,9]]
r = tf.reshape(l, [9,-1])
print(l, type(l))
print(r, type(r))
因此列表 dec_res
包含 tf.tensor 个对象。这对我来说似乎是合理的。但是根据文档,普通字符串也是 'Tensor' 吗?
然后我用 tf.reshape
函数尝试了一些其他的东西。在文档 https://www.tensorflow.org/api_docs/python/tf/reshape 中它说 'tensor: A Tensor.' 所以,l
应该是一个张量。但它不是 tf.tensor
类型,而只是 python list
类型。这令人困惑。
然后文档说
Returns:
A Tensor. Has the same type as tensor.
但是 l
的类型是 list
而 r
的类型是 tensorflow.python.framework.ops.Tensor
。所以类型不一样。
然后我认为 TensorFlow 非常慷慨地将事物作为张量。所以我尝试了:
class car(object):
def __init__(self, color):
self.color = color
red_car = car('red')
#test_reshape = tf.reshape(red_car, [1, -1])
print(red_car.color) # to check, that red_car exists.
现在,注释中的行导致错误。
所以,谁能帮我找出什么才算 'Tensor'?
P.S.: 我试图阅读文档
中给出的tf.reshape
的源代码
Defined in tensorflow/python/ops/gen_array_ops.py.
但是 Github 仓库中不存在这个文件。有人知道怎么读吗?
https://www.tensorflow.org/programmers_guide/tensors
TensorFlow, as the name indicates, is a framework to define and run computations involving tensors. A tensor is a generalization of vectors and matrices to potentially higher dimensions. Internally, TensorFlow represents tensors as n-dimensional arrays of base datatypes.
您所观察到的事实是,可以使用函数 tf.convert_to_tensor:
从各种 python 类型构建张量流操作(如重塑)https://www.tensorflow.org/api_docs/python/tf/convert_to_tensor
All standard Python op constructors apply this function to each of their Tensor-valued inputs, which allows those ops to accept numpy arrays, Python lists, and scalars in addition to Tensor objects