Function Differences with torch.max

View Source On Gitee

torch.max

torch.max(
    input,
    dim,
    keepdim=False,
    out=None
)

For more information, see torch.max.

mindspore.ops.ArgMaxWithValue

class mindspore.ops.ArgMaxWithValue(
    axis=0,
    keep_dims=False
)(input_x)

For more information, see mindspore.ops.ArgMaxWithValue.

Differences

PyTorch: Output tuple(max, index of max).

MindSpore: Output tuple(index of max, max).

Code Example

import mindspore as ms
import mindspore.ops as ops
import torch
import numpy as np

# Output tuple(index of max, max).
input_x = ms.Tensor(np.array([0.0, 0.4, 0.6, 0.7, 0.1]), ms.float32)
argmax = ops.ArgMaxWithValue()
index, output = argmax(input_x)
print(index)
print(output)
# Out:
# 3
# 0.7

# Output tuple(max, index of max).
input_x = torch.tensor([0.0, 0.4, 0.6, 0.7, 0.1])
output, index = torch.max(input_x, 0)
print(index)
print(output)
# Out:
# tensor(3)
# tensor(0.7000)