slkingxr
slkingxr

Reputation: 51

How to get the maximum and secondary maximum values of each row in a matrix in tensorflow?

How to get the maximum and secondary maximum values of each row in a matrix in tensorflow? E.g. I have a matrix tensor as [[1,2,3],[6,5,4],[7,9,8]]. Then I want to get the maximum value vector of each row like [3,6,9] and the secondary value vector[2,4,8]. May be the question can be split into two parts: 1.find the value indexes 2.collect the values from matrix and form a new vector.

Upvotes: 0

Views: 285

Answers (1)

Patwie
Patwie

Reputation: 4450

You might want to use tf.nn.top_k which does exactly what you are looking for:

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)

Upvotes: 1

Related Questions