代码拉取完成,页面将自动刷新
torch.nn.init.uniform_(
tensor,
a=0.0,
b=1.0
) -> Tensor
For more information, see torch.nn.init.uniform_.
mindspore.ops.uniform(shape, minval, maxval, seed=None, dtype=mstype.float32) -> Tensor
For more information, see mindspore.ops.uniform.
PyTorch: The upper and lower bounds of uniform distribution are specified by parameters a
and b
, i.e. U(-a, b).
MindSpore: The upper and lower bounds of uniform distribution are specified by parameters minval
and maxval
, i.e. U(minval, maxval),seed
is used for random number generator to generate pseudorandom numbers.
Categories | Subcategories | PyTorch | MindSpore | Difference |
---|---|---|---|---|
Parameters | Parameter 1 | tensor | shape | The function is similar, but the input format is not.tensor is an n-dimensional tensor on Pytorch, but shape is a shape of random tensor to be generated on MindSpore platform. |
Parameter 2 | a | minval | They have different names and similar functions, which are used to specify the minimum value of random values generated. | |
Parameter 3 | b | maxval | They have different names and similar functions, which are used to specify the maximum value of random values generated. | |
Parameter 4 | - | seed | Seed is used as entropy source for the random number engines to generate pseudo-random numbers, must be non-negative. | |
Parameter 5 | - | dtype | Specify the type of input data, and determine whether the data generated by uniform distribution is discrete or continuous according to the data type. |
# PyTorch
import torch
from torch import nn
w = torch.empty(3, 2)
output = nn.init.uniform_(w, a=1, b=4)
print(tuple(output.shape))
# (3, 2)
# MindSpore
import numpy as np
import mindspore
from mindspore import ops
from mindspore import Tensor
shape = (3,2)
minval = Tensor(1, mindspore.float32)
maxval = Tensor(4, mindspore.float32)
output = ops.uniform(shape, minval, maxval, dtype=mindspore.float32)
print(output.shape)
# Out:
# (3, 2)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。