The Python Oracle

TensorFlow: argmax (-min)

This video explains
TensorFlow: argmax (-min)

--

Become part of the top 3% of the developers by applying to Toptal
https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Droplet of life

--

Chapters
00:00 Question
01:56 Accepted answer (Score 21)
02:32 Answer 2 (Score 1)
03:17 Thank you

--

Full question
https://stackoverflow.com/questions/3809...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #arrays #indexing #tensorflow

#avk47



ACCEPTED ANSWER

Score 21


Think of the dimension argument of tf.argmax as the axis across which you reduce. tf.argmax(arr, 0) reduces across dimension 0, i.e. the rows. Reducing across rows means that you will get the argmax of each individual column.

This might be counterintuitive, but it falls in line with the conventions used in tf.reduce_max and so on.




ANSWER 2

Score 1


In an n-dimensional Tensor, any given dimension has n-1 dimensions that form a discrete 2 dimensional subspace. Following the same logic, it has n-2 3 dimensional subspaces, all the way down to n - (n-1), n dimensional subspaces. You could express any aggregation as a function within the remaining subspace(s), or across the subspace(s) that are being aggregated. Since the subspace will no longer exist after the aggregation, Tensorflow has chosen to implement it as an operation across that dimension.

Frankly, it's an implementation choice by the creators of Tensorflow, now you know.