小编Uih*_* Jo的帖子

如何在 TensorFlow 中将张量转换为 ndarray?

我的目标是将张量转换为没有 'run' 或 'eval' 的 ndarray。我想执行与示例相同的操作。

A = tf.constant(5)
B = tf.constant([[A, 1], [0,0]])
Run Code Online (Sandbox Code Playgroud)

但是, ndarray 可以在 tf.constant 内部,但 tensor 不能。因此,我尝试使用以下示例执行操作,但 tf.make_ndarray 不起作用。

A = tf.constant(5)
C = tf.make_ndarray(A)
B = tf.constant([[C, 1], [0,0]])
Run Code Online (Sandbox Code Playgroud)

https://github.com/tensorflow/tensorflow/issues/28840#issuecomment-509551333

正如上面 github 链接中提到的, tf.make_ndarray 不起作用。准确地说,发生错误是因为 tensorflow 需要一个不存在的 'tensor_shape',而不是一个存在的 'shape'。

在这种情况下如何运行代码?

python tensorflow

3
推荐指数
1
解决办法
1113
查看次数

标签 统计

python ×1

tensorflow ×1