Learn python theano.tensor.argmax() by examples

Description:

theano.tensor.argmax(x, axis=None, keepdims=False)

return the index of the maximum value along a given axis

Parameters:

x: a Theano TensorVariable type
axis: axis along which to compute the index of the maximum

Examples:

1.Get the max number Index in a maxtix

import theano
import theano.tenser as T
import numpy

Define a matrix

matrix_x = T.dmatrix()

max_index = T.argmax(matrix_x)

get_max_index = theano.function([matrix_x], max_index)

matrix_input = numpy.asarray([[1, 2, 3],[2, 2, 4]])

print get_max_index(matrix_input)

output:5

If you want to get max number index by row, you shoud edit T.argmax

max_index = T.argmax(matrix_x, axis= 1)
get_max_index = theano.function([matrix_x], max_index)

matrix_input = numpy.asarray([[1, 2, 3],[2, 2, 4]])

print get_max_index(matrix_input)

output:[2, 2]

Leave a Reply

Your email address will not be published. Required fields are marked *