如何在tensorflow中求矩阵中每一行的最大值和次最大值?

2024-04-30 06:43:20 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在tensorflow中求矩阵中每一行的最大值和次最大值?例如,我有一个矩阵张量[[1,2,3],[6,5,4],[7,9,8]]。然后我想得到每一行的最大值向量,如[3,6,9]和次值向量[2,4,8]。可能问题可以分为两部分:1.寻找价值指标2.从矩阵中收集价值并形成新的向量


Tags: tensorflow矩阵指标向量价值中求次值
1条回答
网友
1楼 · 发布于 2024-04-30 06:43:20

您可能希望使用tf.nn.top_k,它正好满足您的要求:

Finds values and indices of the k largest entries for the last dimension. ... For matrices (resp. higher rank input), computes the top k entries in each row (resp. vector along the last dimension)

相关问题 更多 >