pandas - 获取 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,但我不知道如何在组中使用它。
解决方案
推荐阅读
- ssh - 连接到本地 gitlab 实例时的 kex_exchange_identification
- android - 暴露的下拉菜单 - 没有来自 xml 资源的过滤器
- mongodb - Mongo合并结果
- javascript - 如何使用动态 VAR 在 Javascript 中创建动态函数
- javascript - 如何在 javascript 中运行 jar 文件?
- python - 列表列表中字符串长度的总和
- flutter - 是否可以将 ReorderableListView 项目拖到另一个 ReorderableListView?
- azure - Blazor 应用页面中的 JWT 令牌需要加载两次才能验证令牌
- jackson - 执行我的项目给出错误 NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
- audio - 使用ffmpeg将视频转换为hls后,新视频没有屏幕,只有音频