Function Differences with tf.arg_min
tf.arg_min
tf.arg_min(input, dimension, output_type=tf.dtypes.int64, name=None)
For more information, see tf.arg_min.
mindspore.Tensor.argmin
mindspore.Tensor.argmin(axis=None)
For more information, see mindspore.Tensor.argmin.
Usage
Same function. Two interfaces of MindSpore and TensorFlow decide on which dimension to return the index of the minimum value through the parameters axis
and dimension
, respectively.
The difference is that in the default state, axis=None
of MindSpore returns the global index of the minimum value; TensorFlow dimension
returns the minimum index of dimension=0
by default when no value is passed in.
Code Example
import mindspore as ms
a = ms.Tensor([[1, 10, 166.32, 62.3], [1, -5, 2, 200]], ms.float32)
print(a.argmin())
print(a.argmin(axis=0))
print(a.argmin(axis=1))
# output:
# 5
# [0 1 1 0]
# [0 1]
import tensorflow as tf
tf.enable_eager_execution()
b = tf.constant([[1, 10, 166.32, 62.3], [1, -5, 2, 200]])
print(tf.argmin(b).numpy())
print(tf.argmin(b, dimension=0).numpy())
print(tf.argmin(b, dimension=1).numpy())
# output:
# [0 1 1 0]
# [0 1 1 0]
# [0 1]