【问题标题】:Python tensorflow complex number operationPython tensorflow 复数运算
【发布时间】:2018-07-23 23:44:45
【问题描述】:

我正在使用 Edward(1.3.5) 和 Tensorflow(1.6.0,-gpu 版本) 进行建模和变分推理。但是,当尝试对复数进行一些操作时,发生错误“ValueError: Tensor conversion requested dtype complex64 for Tensor with dtype float32”。这是一个简化示例,但也会导致相同的错误:

import tensorflow as tf
tf.complex(1., 1.) * tf.sqrt(1.)**2

complex 和 sqrt 的结果之间的 dtype 似乎有冲突? 此外,我还尝试将 sqrt 的结果转换为 float64,但收到一些错误:

tf.complex(1., 1.) * tf.cast(sqrt(1.), tf.float64)**2

有什么解决办法吗? 谢谢。

【问题讨论】:

  • 将其转换为 complex64 而不是 float64
  • 是的,它有效!!谢谢。
  • 你能投票并接受我的回答吗?

标签: python python-3.x tensorflow


【解决方案1】:

问题是将数字转换为 complex64 而不是 float 64

tf.complex(1., 1.) * tf.cast(sqrt(1.), tf.complex64)**2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-18
    • 2016-05-07
    • 2019-10-16
    • 1970-01-01
    • 2011-05-07
    • 2012-02-20
    • 1970-01-01
    相关资源
    最近更新 更多