tf.ones返回0而不是1

2024-10-01 00:32:53 发布

您现在位置:Python中文网/ 问答频道 /正文

为什么tf.ones返回零?我的版本是'2.3.0',我使用的是Python环境

import tensorflow as tf

tf.ones((3, 3))
<tf.Tensor: shape=(3, 3), dtype=float32, numpy=
array([[0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 0.]], dtype=float32)>

我不明白发生了什么。。。但是如果我使用dtypetf.int32,它可以工作:

tf.ones((3, 3), dtype=tf.int32)
<tf.Tensor: shape=(3, 3), dtype=int32, numpy=
array([[1, 1, 1],
       [1, 1, 1],
       [1, 1, 1]])>

有人有同样的问题


Tags: import版本numpy环境tftensorflowasones