问题
Why is tf.ones
returning zeros? My version is '2.3.0'
and I'm using an Anaconda environment.
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)>
I don't understand what's going on... But if I use dtype tf.int32
it works:
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]])>
Someone here had the same issue.
回答1:
Perhaps, your Python installation doesn't support tensorflow 2.3.0. For instance, Anaconda works properly only with TF 2.1.0
来源:https://stackoverflow.com/questions/63363859/tf-ones-returns-zeros-instead-of-ones