tf.argmaxおよびtf.arg_max



Tf Argmax Tf Arg_max



Tf.arg_max tf.argmax同じ使用法、以下に説明する使用法tf.argmax

tf.argmax

def argmax(input, axis=None, name=None, dimension=None, output_type=dtypes.int64) numpy.argmax(a, axis=None, out=None) Returns the index of the maximum value along the shaft axis. Parameters: input: array_like, array axis : int, The optional, by default, the index of the array is tiled, or shaft along specified. out : Array, optional if provided, result in a suitable shape and type are inserted into this array. Returns: index_array : ndarray of ints Indexed array. It has a.shapeThe same shape, wherein the axis is removed.

使用法tf.argmax()およびnumpy.argmax()メソッドは一貫しています



各列インデックスの最大戻り位置の場合、axis = 0
各インデックスの最大値の位置に戻るとき、axis = 1
axis = 2,3,4 ...、つまり、多次元テンソル、共感推論の場合

>>> a = np.arange(6).reshape(2,3) >>> a array([[0, 1, 2], [3, 4, 5]]) >>> np.argmax(a) 5 >>> np.argmax(a, axis=0) # 0 represents the column array([1, 1, 1]) >>> np.argmax(a, axis=1) # 1 represents the line array([2, 2]) >>> >>> b = np.arange(6) >>> b[1] = 5 >>> b array([0, 5, 2, 3, 4, 5]) >>> np.argmax(b) # Only returns the index of the first occurrence of the maximum value 1

tf.arg_max()

以下はargmaxのソースコードです(から https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/math_ops.py )。



# pylint: disable=redefined-builtin # TODO(aselle): deprecate arg_max def argmax(input, axis=None, name=None, dimension=None): if dimension is not None: if axis is not None: raise ValueError('Cannot specify both 'axis' and 'dimension'') axis = dimension elif axis is None: axis = 0 return gen_math_ops.arg_max(input, axis, name)

ご覧のとおり、argmaxは内部でarg_maxを使用しています。また、コードから、arg_maxは間もなく非推奨になる可能性があるため、argmaxを使用することをお勧めします。