March 2019
Intermediate to advanced
196 pages
4h 50m
English
We will now look at how to find the indices of the elements with the largest and smallest values, respectively, across the axes of a tensor.
The signatures of the functions are as follows:
tf.argmax(input, axis=None, name=None, output_type=tf.int64 )tf.argmin(input, axis=None, name=None, output_type=tf.int64 )
Take this, for example:
# 1-D tensort5 = tf.constant([2, 11, 5, 42, 7, 19, -6, -11, 29])print(t5)i = tf.argmax(input=t5)print('index of max; ', i)print('Max element: ',t5[i].numpy())i = tf.argmin(input=t5,axis=0).numpy()print('index of min: ', i)print('Min element: ',t5[i].numpy())t6 = tf.reshape(t5, [3,3])print(t6)i = tf.argmax(input=t6,axis=0).numpy() # max arg down rowsprint('indices ...Read now
Unlock full access