首页 > 解决方案 > 获取 tensorflow 段中最大值的 id

问题描述

我想获取 tensorflow 段内最大值的 id。

如果我将它类比为熊猫,我想要类似的东西:

 df.groupby(by="id")[["O","Dn"]].apply(lambda x: x["Dn"].loc[x["O"].idxmax()])

因此,对于每个组,我在一个列中查找最大值,但我从该最大值行返回另一个值。

从 Tensorflow 我知道这样的事情:

unique, idx, count = tf.unique_with_counts(df["id"])
group_max = tf.math.unsorted_segment_max(df.loc[:,["O","Dn"]].values, idx, len(unique))

当然,这只查找每列的最大值,这与我想要的不同。

我知道 tensorflow 有 argmax,但我不知道如何在组中使用它。

标签: pandastensorflowtensorsegment

解决方案


推荐阅读