Trying out tensorflow api

Is there a place where I can try out tensorflow api. The official documentation from Google is not clear for argmax: tf.math.argmax  |  TensorFlow Core v2.8.0

I want to try out these commands in the example. It is not at all clear what the output of argmax is. So frustrating!

A = tf.constant([2, 20, 30, 3, 6])
tf.math.argmax(A)  # A[2] is maximum in tensor A

B = tf.constant([[2, 20, 30, 3, 6], [3, 11, 16, 1, 8],
                 [14, 45, 23, 5, 27]])
tf.math.argmax(B, 0)

tf.math.argmax(B, 1)

C = tf.constant([0, 0, 0, 0])
tf.math.argmax(C) # Returns smallest index in case of ties

OK, I found out – Just create a new cell in the workbook and try it out yourself :slight_smile:

1 Like

Hey Vijayst,

First off: Welcome to the discourse! Second off: the tf.math.argmax returns the the index, or indices, of the largest values across the specific axis.

Let’s walk through the examples to see what that means:

Ex 1.:

if A = tf.constant([2, 20, 30, 3, 6]) the tf.math.argmax(A) is index 2. The reason for this is that index 2 is the maximum value in the A tensor. (30 is the maximum value in the tensor, and 30 is in the position 2!

Ex 2.:

In the case of multiple axis (i.e. a 2D tensor), and specifying an index, it will return the index associated with the maximum value in that axis.

Hopefully this helps! :smile:

That’s awesome news! I’m glad you figured it out! :smiley:

Thanks Alex, very helpful.

1 Like

Glad to hear you figured this out on your own! For anyone else who sees this later, to add a cell for testing like this as Vijay described, use the menu option “Insert → Cell Below”. Then you can add whatever test code you want in that new cell. To be on the safe side, just make sure not to reuse the names of any global variables that are defined elsewhere in the notebook.