tf.ones returns zeros instead of ones

两盒软妹~` 提交于 2021-02-10 15:41:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!