英文:
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 '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]
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)
>>>(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))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论