【发布时间】:2019-06-27 21:25:17
【问题描述】:
我刚刚注意到这个奇怪的张量:
Out[124]: <tf.Tensor: id=7672038, shape=(1,), dtype=uint8, numpy=array([1], dtype=uint8)>
它有两次 dtype。通常,您无法得到它。例如,
tf.convert_to_tensor(np.array([1]))
Out[126]: <tf.Tensor: id=7672042, shape=(1,), dtype=int32, numpy=array([1])>
为什么会这样,有什么区别?
我刚刚注意到:后者可以用作张量的索引,但前者不能。它抛出这个错误:
TypeError: 只有整数、切片 (
:)、省略号 (...)、tf.newaxis (None) 和标量 tf.int32/tf.int64 张量是有效的索引,得到 1
这是一个愚蠢的错误,因为它说“得到 1”,而 1 是一个合法的索引!因为它是大声喊叫的整数!请参阅上面的 dtype。
【问题讨论】:
-
也许你应该为你从哪里得到这个“奇怪的张量”添加一些上下文。
-
@xdurch0 我从 tf.dataset.from_tensor_slices 得到它我用 numpy 数组喂它
标签: numpy tensorflow