# Differences with torch.distributions.laplace.Laplace [![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/r2.3.q1/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/r2.3.q1/docs/mindspore/source_en/note/api_mapping/pytorch_diff/standard_laplace.md) ## torch.distributions.laplace.Laplace ```text torch.distributions.laplace.Laplace(loc, scale) -> Class Instance ``` For more information, see [torch.distributions.laplace.Laplace](https://pytorch.org/docs/1.8.1/distributions.html#torch.distributions.laplace.Laplace). ## mindspore.ops.standard_laplace ```text mindspore.ops.standard_laplace(shape, seed=None) -> Tensor ``` For more information, see [mindspore.ops.standard_laplace](https://mindspore.cn/docs/en/r2.3.0rc1/api_python/ops/mindspore.ops.standard_laplace.html). ## Differences PyTorch: Create a Laplace distribution instance and call the sample interface of the instance to generate random values that match the Laplace distribution. MindSpore: Generates random numbers that match the standard Laplace (mean=0, lambda=1) distribution. When loc=0, scale=1 in PyTorch and the sample function input shape is the same as MindSpore, the two APIs achieve the same function. | Categories | Subcategories | PyTorch | MindSpore | Differences | | ---- | ----- | ------- | --------- | -------------- | | Parameters | Parameter 1 | loc | - | MindSpore does not have this parameter and implements loc=0 in PyTorch by default | | | Parameter 2 | scale | - | MindSpore does not have this parameter and implements scale=1 in PyTorch by default | | | Parameter 3 | - | shape | This parameter in PyTorch is passed in when the sample interface is called | | | Parameter 4 | - | seed | Random seeds for the operator layer. PyTorch does not have this parameter | ### Code Example > Each randomly generated value in PyTorch occupies one dimension, so the innermost layer of the shape passed in MindSpore adds a dimension of length 1, and the two APIs achieve the same function. ```python # PyTorch import torch m = torch.distributions.laplace.Laplace(torch.tensor([0.0]), torch.tensor([1.0])) shape = (4, 4) sample = m.sample(shape) print(tuple(sample.shape)) # (4, 4, 1) # MindSpore import mindspore from mindspore import ops shape = (4, 4, 1) output = ops.standard_laplace(shape) result = output.shape print(result) # (4, 4, 1) ```