使用TensorFlow对复数进行reduce max。

huangapple go评论74阅读模式
英文:

Use tensorflow reduce max on complex numbers

问题

让我们假设我有这个张量:

h = tf.constant([1.+2.j, 3 + 4.j])

而我想在它上面使用tf.reduce_max

tf.reduce_max(h)

我会得到以下错误:

InvalidArgumentError: Value for attr 'T' of complex128 is not in the list of allowed values: float, double, int32, uint8, int16, int8, int64, bfloat16, uint16, half, uint32, uint64, qint8, quint8, qint32, qint16, quint16
; NodeDef: {{node Max}}; Op<name=Max; signature=input:T, reduction_indices:Tidx -> output:T; attr=keep_dims:bool,default=false; attr=T:type,allowed=[DT_FLOAT, DT_DOUBLE, DT_INT32, DT_UINT8, DT_INT16, 12026250066093653660, DT_QINT8, DT_QUINT8, DT_QINT32, DT_QINT16, DT_QUINT16]; attr=Tidx:type,default=DT_INT32,allowed=[DT_INT32, DT_INT64]> [Op:Max]

然而,当我尝试使用NumPy时,没有错误:

h_array = np.array([1.+2.j, 3 +4.j])
np.max(h_array)
# 输出:(3+4j)

如何让它在TensorFlow上工作?谢谢。

英文:

Let's say I have this tensor:

h = tf.constant([1.+2.j, 3 + 4.j])

And i want to use the tf.reduce_max on it:

tf.reduce_max(h)

I will have the following error:

InvalidArgumentError: Value for attr &#39;T&#39; of complex128 is not in the list of allowed values: float, double, int32, uint8, int16, int8, int64, bfloat16, uint16, half, uint32, uint64, qint8, quint8, qint32, qint16, quint16
	; NodeDef: {{node Max}}; Op&lt;name=Max; signature=input:T, reduction_indices:Tidx -&gt; output:T; attr=keep_dims:bool,default=false; attr=T:type,allowed=[DT_FLOAT, DT_DOUBLE, DT_INT32, DT_UINT8, DT_INT16, 12026250066093653660, DT_QINT8, DT_QUINT8, DT_QINT32, DT_QINT16, DT_QUINT16]; attr=Tidx:type,default=DT_INT32,allowed=[DT_INT32, DT_INT64]&gt; [Op:Max]

Where, when I am trying with numpy there is no error:

h_array = np.array([1.+2.j, 3 +4.j])
np.max(h_array)
&gt;&gt;&gt;(3+4j)

How can I make it work on tensorflow.
Thanks

答案1

得分: 1

Numpy只比较复数的实部(查看这里)。

所以你应该尝试 tf.reduce_max(tf.math.real(h))

英文:

Numpy only compares the real part of the complex numbers (compare here).

So you should probably try tf.reduce_max(tf.math.real(h))

huangapple
  • 本文由 发表于 2023年6月26日 21:17:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76557071.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定