gpt4 book ai didi

python - Tensorflow - 从 int 转换为 float 奇怪的行为

转载 作者:太空狗 更新时间:2023-10-29 17:08:53 38 4
gpt4 key购买 nike

我正在处理 tensorflow 0.12,但在转换时遇到问题。下面的代码片段做了一件奇怪的事情:

sess = tf.InteractiveSession()
a = tf.constant(1)
b = tf.cast(a, tf.float32)
print b.eval()

我得到一个值:6.86574233e-36

我还尝试使用 tf.to_float()tf.saturate_cast。两者都给出了相同的结果。

请帮忙。

最佳答案

sess = tf.InteractiveSession()
a = tf.constant(1, tf.int64) <--------
b = tf.cast(a, tf.float32)
print b.eval() # 1.0

您需要为您的tf.constant 声明dtype:https://www.tensorflow.org/api_docs/python/tf/constant

关于python - Tensorflow - 从 int 转换为 float 奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42364629/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com