比较与torch.exp的功能差异

torch.exp

torch.exp(input, *, out=None) -> Tensor

更多内容详见torch.exp

mindspore.ops.exp

mindspore.ops.exp(x) -> Tensor

更多内容详见mindspore.ops.exp

差异对比

PyTorch:逐元素计算输入张量input的指数。

MindSpore:MindSpore此API实现功能与PyTorch一致,仅参数名不同。

分类

子类

PyTorch

MindSpore

差异

参数

参数1

input

x

功能一致,参数名不同

参数2

out

-

不涉及

代码示例1

两API实现功能一致,用法相同。

# PyTorch
import torch
from torch import tensor

x = tensor([[0, 1, 2], [0, -1, -2]], dtype=torch.float32)
out = torch.exp(x).numpy()
print(out)
# [[1.         2.7182817  7.389056  ]
#  [1.         0.36787945 0.13533528]]

# MindSpore
import mindspore
from mindspore import Tensor
import numpy as np

x = Tensor(np.array([[0, 1, 2], [0, -1, -2]]), mindspore.float32)
output = mindspore.ops.exp(x)
print(output)
# [[1.         2.718282   7.3890557 ]
#  [1.         0.36787948 0.13533528]]

代码示例2

两API实现功能一致,用法相同。

# PyTorch
import torch
from torch import tensor
import math

x = tensor([-1, 1, math.log(2.0)], dtype=torch.float32)
out = torch.exp(x).numpy()
print(out)
# [0.36787945 2.7182817  2.        ]

# MindSpore
import mindspore
from mindspore import Tensor
import math

x = Tensor([-1, 1, math.log(2.0)], mindspore.float32)
output = mindspore.ops.exp(x)
print(output)
# [0.36787948 2.718282   2.        ]