| @@ -0,0 +1,44 @@ | |||
| mindspore.nn.FastGelu | |||
| ====================== | |||
| .. py:class:: mindspore.nn.FastGelu | |||
| 快速高斯误差线性单元激活函数(Fast Gaussian Error Linear Units activation function)。 | |||
| 对输入的每个元素计算FastGelu。 | |||
| FastGelu定义如下: | |||
| .. math:: | |||
| FastGelu(x_i) = \frac {x_i} {1 + \exp(-1.702 * \left| x_i \right|)} * | |||
| \exp(0.851 * (x_i - \left| x_i \right|)) | |||
| 其中 :math:`x_i` 是输入的元素。 | |||
| **输入:** | |||
| - **x** (Tensor):用于计算FastGelu的Tensor。数据类型为float16或float32。shape为 :math:`(N,*)`,其中 :math:`*` 表示任意的附加维度数。 | |||
| **输出:** | |||
| Tensor,具有与 `x` 相同的数据类型和shape。 | |||
| **异常:** | |||
| - **TypeError:** `x` 的数据类型既不是float16也不是float32。 | |||
| **支持平台:** | |||
| ``Ascend`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32) | |||
| >>> fast_gelu = nn.FastGelu() | |||
| >>> output = fast_gelu(x) | |||
| >>> print(output) | |||
| [[-1.5418735e-01 3.9921875e+00 -9.7473649e-06] | |||
| [ 1.9375000e+00 -1.0052517e-03 8.9824219e+00]] | |||
| @@ -0,0 +1,42 @@ | |||
| mindspore.nn.HSwish | |||
| =================== | |||
| .. py:class:: mindspore.nn.HSwish | |||
| Hard Swish激活函数。 | |||
| 对输入的每个元素计算Hard Swish。 | |||
| Hard Swish定义如下: | |||
| .. math:: | |||
| \text{hswish}(x_{i}) = x_{i} * \frac{ReLU6(x_{i} + 3)}{6}, | |||
| 其中, :math:`x_i` 是输入的元素。 | |||
| **输入:** | |||
| - **x** (Tensor) - 用于计算Hard Swish的Tensor。数据类型必须是float16或float32。shape为 :math:`(N,*)`,其中 :math:`*` 表示任意的附加维度数。 | |||
| **输出:** | |||
| Tensor,具有与 `x` 相同的数据类型和shape。 | |||
| **异常:** | |||
| - **TypeError:** `x` 的数据类型既不是float16也不是float32。 | |||
| **支持平台:** | |||
| ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> x = Tensor(np.array([-1, -2, 0, 2, 1]), mindspore.float16) | |||
| >>> hswish = nn.HSwish() | |||
| >>> result = hswish(x) | |||
| >>> print(result) | |||
| [-0.3333 -0.3333 0 1.666 0.6665] | |||
| @@ -0,0 +1,41 @@ | |||
| mindspore.nn.ReLU | |||
| ================= | |||
| .. py:class:: mindspore.nn.ReLU | |||
| 修正线性单元激活函数(Rectified Linear Unit activation function)。 | |||
| 按元素返回 :math:`\max(x,\ 0)`。特别说明,负数输出值会被修改为0,正数输出不受影响。 | |||
| .. math:: | |||
| \text{ReLU}(x) = (x)^+ = \max(0, x), | |||
| ReLU相关图参见 `ReLU <https://en.wikipedia.org/wiki/Activation_function#/media/File:Activation_rectified_linear.svg>`_ 。 | |||
| **输入:** | |||
| - **x** (Tensor):用于计算ReLU的Tensor。数据类型为Number。shape为 :math:`(N,*)`,其中 :math:`*` 表示任意的附加维度数。 | |||
| **输出:** | |||
| Tensor,具有与 `x` 相同的数据类型和shape。 | |||
| **异常:** | |||
| - **TypeError:** `x` 的数据类型不是Number。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> x = Tensor(np.array([-1, 2, -3, 2, -1]), mindspore.float16) | |||
| >>> relu = nn.ReLU() | |||
| >>> output = relu(x) | |||
| >>> print(output) | |||
| [0. 2. 0. 2. 0.] | |||
| @@ -0,0 +1,50 @@ | |||
| mindspore.nn.ELU | |||
| ================= | |||
| .. py:class:: mindspore.nn.ELU(alpha=1.0) | |||
| 指数线性单元激活函数(Exponential Linear Uint activation function)。 | |||
| 对输入的每个元素计算ELU。该激活函数定义如下: | |||
| .. math:: | |||
| E_{i} = | |||
| \begin{cases} | |||
| x, &\text{if } x \geq 0; \cr | |||
| \text{alpha} * (\exp(x_i) - 1), &\text{otherwise.} | |||
| \end{cases} | |||
| ELU相关图参见 `ELU <https://en.wikipedia.org/wiki/Activation_function#/media/File:Activation_elu.svg>`_ 。 | |||
| **参数** : | |||
| - **alpha** (`float`) – ELU的alpha值,数据类型为浮点数。默认值:1.0。 | |||
| **输入** : | |||
| - **x** (Tensor) - 用于计算ELU的Tensor,数据类型为float16或float32。shape为 :math:`(N,*)` ,:math:`*` 表示任意的附加维度数。 | |||
| **输出** : | |||
| Tensor,具有与 `x` 相同的数据类型和shape。 | |||
| **异常** : | |||
| - **TypeError:** `alpha` 不是浮点数。 | |||
| - **TypeError:** `x` 的数据类型既不是float16也不是float32。 | |||
| - **ValueError:** `alpha` 不等于1.0。 | |||
| **支持平台** : | |||
| `Ascend` `GPU` `CPU` | |||
| **样例** : | |||
| .. code-block:: | |||
| >>> x = Tensor(np.array([-1, -2, 0, 2, 1]), mindspore.float32) | |||
| >>> elu = nn.ELU() | |||
| >>> result = elu(x) | |||
| >>> print(result) | |||
| [-0.63212055 -0.86466473 0. 2. 1.] | |||
| @@ -0,0 +1,45 @@ | |||
| mindspore.nn.GELU | |||
| ================== | |||
| .. py:class:: mindspore.nn.GELU | |||
| 高斯误差线性单元激活函数(Gaussian error linear unit activation function)。 | |||
| 对输入的每个元素计算GELU。 | |||
| GELU的定义如下: | |||
| .. math:: | |||
| GELU(x_i) = x_i*P(X < x_i), | |||
| 其中 :math:`P` 是标准高斯分布的累积分布函数, :math:`x_i` 是输入的元素。 | |||
| GELU相关图参见 `GELU <https://en.wikipedia.org/wiki/Activation_function#/media/File:Activation_gelu.png>`_ 。 | |||
| **输入** : | |||
| - **x** (Tensor) - 用于计算GELU的Tensor。数据类型为float16或float32。shape是 :math:`(N,*)` , :math:`*` 表示任意的附加维度数。 | |||
| **输出** : | |||
| Tensor,具有与 `x` 相同的数据类型和shape。 | |||
| **异常** : | |||
| - **TypeError:** `x` 的数据类型既不是float16也不是float32。 | |||
| **支持平台** : | |||
| `Ascend` `GPU` `CPU` | |||
| **样例** : | |||
| .. code-block:: | |||
| >>> x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32) | |||
| >>> gelu = nn.GELU() | |||
| >>> output = gelu(x) | |||
| >>> print(output) | |||
| [[-1.5880802e-01 3.9999299e+00 -3.1077917e-21] | |||
| [ 1.9545976e+00 -2.2918017e-07 9.0000000e+00]] | |||
| @@ -0,0 +1,56 @@ | |||
| mindspore.ops.Add | |||
| ================= | |||
| .. py:class:: mindspore.ops.Add(*args, **kwargs) | |||
| 两个输入Tensor按元素相加。 | |||
| 输入 `x` 和 `y` 遵循隐式类型转换规则,使数据类型保持一致。 | |||
| 输入必须是两个Tensor,或一个Tensor和一个Scalar。 | |||
| 当输入是两个Tensor时,它们的数据类型不能同时是bool,它们的shape可以广播。 | |||
| 当输入是一个Tensor和一个Scalar时,Scalar只能是一个常数。 | |||
| .. math:: | |||
| out_{i} = x_{i} + y_{i} | |||
| **输入:** | |||
| - **x** (Union[Tensor, Number, bool]) - 第一个输入,是一个Number、bool值或数据类型为Number或bool的Tensor。 | |||
| - **y** (Union[Tensor, Number, bool]) - 第二个输入,当第一个输入是Tensor时,第二个输入应该是一个Number或bool值,或数据类型为Number或bool的Tensor。 | |||
| **输出:** | |||
| Tensor,shape与广播后的shape相同,数据类型为两个输入中精度较高的类型。 | |||
| **异常:** | |||
| - **TypeError:** `x` 和 `y` 不是Tensor、Number或bool。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> # 用例1: x和y都是Tensor。 | |||
| >>> add = ops.Add() | |||
| >>> x = Tensor(np.array([1, 2, 3]).astype(np.float32)) | |||
| >>> y = Tensor(np.array([4, 5, 6]).astype(np.float32)) | |||
| >>> output = add(x, y) | |||
| >>> print(output) | |||
| [5.7.9.] | |||
| >>> # 用例2: x是Scalar Tensor,y是Tensor。 | |||
| >>> add = ops.Add() | |||
| >>> x = Tensor(1, mindspore.int32) | |||
| >>> y = Tensor(np.array([4, 5, 6]).astype(np.float32)) | |||
| >>> output = add(x, y) | |||
| >>> print(output) | |||
| [5. 6. 7.] | |||
| >>> # x的数据类型为int32,y的数据类型为float32。 | |||
| >>> # 输出的数据类型为高精度float32。 | |||
| >>> print(output.dtype) | |||
| Float32 | |||
| @@ -0,0 +1,44 @@ | |||
| mindspore.ops.AddN | |||
| =================== | |||
| .. py:class:: mindspore.ops.AddN(*args, **kwargs) | |||
| 按元素将所有输入的Tensor相加。 | |||
| 所有输入Tensor必须具有相同的shape。 | |||
| **输入:** | |||
| - **x** (Union(tuple[Tensor], list[Tensor])) - 输入tuple或list由多个Tensor组成,其数据类型为Number或bool,用于相加。 | |||
| **输出:** | |||
| Tensor,与 `x` 的每个Tensor具有相同的shape和数据类型。 | |||
| **异常:** | |||
| - **TypeError:** `x` 既不是tuple,也不是list。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> class NetAddN(nn.Cell): | |||
| ... def __init__(self): | |||
| ... super(NetAddN, self).__init__() | |||
| ... self.addN = ops.AddN() | |||
| ... | |||
| ... def construct(self, *z): | |||
| ... return self.addN(z) | |||
| ... | |||
| >>> net = NetAddN() | |||
| >>> x = Tensor(np.array([1, 2, 3]), mindspore.float32) | |||
| >>> y = Tensor(np.array([4, 5, 6]), mindspore.float32) | |||
| >>> output = net(x, y, x, y) | |||
| >>> print(output) | |||
| [10. 14. 18.] | |||
| @@ -0,0 +1,53 @@ | |||
| mindspore.ops.Div | |||
| ================= | |||
| .. py:class:: mindspore.ops.Div(*args, **kwargs) | |||
| 按元素计算第一输入Tensor除以第二输入Tensor的商。 | |||
| 输入 `x` 和 `y` 遵循隐式类型转换规则,使数据类型保持一致。 | |||
| 输入必须是两个Tensor,或一个Tensor和一个Scalar。 | |||
| 当输入是两个Tensor时,它们的数据类型不能同时是bool,它们的shape可以广播。 | |||
| 当输入是一个Tensor和一个Scalar时,Scalar只能是一个常数。 | |||
| .. math:: | |||
| out_{i} = \frac{x_i}{y_i} | |||
| **输入:** | |||
| - **x** (Union[Tensor, Number, bool]) - 第一个输入,是一个Number、bool值或数据类型为Number或bool的Tensor。 | |||
| - **y** (Union[Tensor, Number, bool]) - 第二个输入,当第一个输入是Tensor时,第二个输入应该是一个Number或bool值,或数据类型为Number或bool的Tensor。 | |||
| **输出:** | |||
| Tensor,shape与广播后的shape相同,数据类型为两个输入中精度较高的类型。 | |||
| **异常:** | |||
| - **TypeError:** `x` 和 `y` 都不是Tensor。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> # 用例1:两个输入的数据类型和shape相同 | |||
| >>> x = Tensor(np.array([-4.0, 5.0, 6.0]), mindspore.float32) | |||
| >>> y = Tensor(np.array([3.0, 2.0, 3.0]), mindspore.float32) | |||
| >>> div = ops.Div() | |||
| >>> output = div(x, y) | |||
| >>> print(output) | |||
| [-1.3333334 2.5 2. ] | |||
| >>> # 用例2:两个输入的数据类型和shape不同 | |||
| >>> x = Tensor(np.array([-4.0, 5.0, 6.0]), mindspore.int32) | |||
| >>> y = Tensor(2, mindspore.float32) | |||
| >>> output = div(x, y) | |||
| >>> print(output) | |||
| [-2. 2.5 3.] | |||
| >>> print(output.dtype) | |||
| Float32 | |||
| @@ -0,0 +1,28 @@ | |||
| mindspore.ops.Eps | |||
| ================= | |||
| .. py:class:: mindspore.ops.Eps(*args, **kwargs) | |||
| 创建一个填充 `x` 数据类型最小值的Tensor。 | |||
| **输入:** | |||
| **x** (Tensor) - 用于获取其数据类型最小值的Tensor。数据类型必须为float16或float32。shape为 :math:`(N,*)`,其中 :math:`*` 表示任意的附加维度数。 | |||
| **输出:** | |||
| Tensor,具有与 `x` 相同的数据类型和shape,填充了 `x` 数据类型的最小值。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> x = Tensor([4, 1, 2, 3], mindspore.float32) | |||
| >>> output = ops.Eps()(x) | |||
| >>> print(output) | |||
| [1.5258789e-05 1.5258789e-05 1.5258789e-05 1.5258789e-05] | |||
| @@ -0,0 +1,37 @@ | |||
| mindspore.ops.Erf | |||
| ================= | |||
| .. py:class:: mindspore.ops.Erf(*args, **kwargs) | |||
| 按元素计算 `x` 的高斯误差函数。 | |||
| .. math:: | |||
| erf(x)=\frac{2} {\sqrt{\pi}} \int\limits_0^{x} e^{-t^{2}} dt | |||
| **输入:** | |||
| **x** (Tensor) - 用于计算高斯误差函数的Tensor。数据类型必须为float16或float32。shape为 :math:`(N,*)`,其中 :math:`*` 表示任意的附加维度数,其秩应小于8。 | |||
| **输出:** | |||
| Tensor,具有与 `x` 相同的数据类型和shape。 | |||
| **异常:** | |||
| **TypeError:** `x` 的数据类型既不是float16也不是float32。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> x = Tensor(np.array([-1, 0, 1, 2, 3]), mindspore.float32) | |||
| >>> erf = ops.Erf() | |||
| >>> output = erf(x) | |||
| >>> print(output) | |||
| [-0.8427168 0. 0.8427168 0.99530876 0.99997765] | |||
| @@ -0,0 +1,49 @@ | |||
| mindspore.ops.Gamma | |||
| =================== | |||
| .. py:class:: mindspore.ops.Gamma(*args, **kwargs) | |||
| 根据概率密度函数分布生成随机正浮点数x。 | |||
| .. math:: | |||
| \text{P}(x|α,β) = \frac{\exp(-x/β)}{{β^α}\cdot{\Gamma(α)}}\cdot{x^{α-1}} | |||
| **参数:** | |||
| - **seed** (int):算子层的随机种子,用于生成随机数。必须是非负的。默认值:0。 | |||
| - **seed2** (int):全局的随机种子,和算子层的随机种子共同决定最终生成的随机数。必须是非负的。默认值:0。 | |||
| **输入:** | |||
| - **shape** (tuple) - 待生成的随机Tensor的shape。只支持常量值。 | |||
| - **alpha** (Tensor) - α为Gamma分布的shape parameter,主要决定了曲线的形状。其值必须大于0。数据类型为float32。 | |||
| - **beta** (Tensor) - β为Gamma分布的inverse scale parameter,主要决定了曲线有多陡。其值必须大于0。数据类型为float32。 | |||
| **输出:** | |||
| Tensor。shape是输入 `shape` 以及alpha、beta广播后的shape。数据类型为float32。 | |||
| **异常:** | |||
| - **TypeError:** `seed` 和 `seed2` 都不是int。 | |||
| - **TypeError:** `alpha` 和 `beta` 都不是Tensor。 | |||
| - **ValueError:** `shape` 不是常量值。 | |||
| **支持平台:** | |||
| ``Ascend`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> shape = (3, 1, 2) | |||
| >>> alpha = Tensor(np.array([[3, 4], [5, 6]]), mstype.float32) | |||
| >>> beta = Tensor(np.array([1.0]), mstype.float32) | |||
| >>> gamma = ops.Gamma(seed=3) | |||
| >>> output = gamma(shape, alpha, beta) | |||
| >>> result = output.shape | |||
| >>> print(result) | |||
| (3, 2, 2) | |||
| @@ -0,0 +1,44 @@ | |||
| mindspore.ops.GeLU | |||
| ================== | |||
| .. py:class:: mindspore.ops.GeLU(*args, **kwargs) | |||
| 高斯误差线性单元激活函数(Gaussian Error Linear Units activation function)。 | |||
| `Gaussian Error Linear Units (GELUs) <https://arxiv.org/abs/1606.08415>`_ 描述了GeLU函数。 | |||
| 此外,也可以参考 `BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding <https://arxiv.org/abs/1810.04805>`_ 。 | |||
| GeLU函数定义如下: | |||
| .. math:: | |||
| \text{output} = 0.5 * x * (1 + tanh(x / \sqrt{2})), | |||
| 其中 :math:`tanh` 是双曲正切函数。 | |||
| **输入:** | |||
| **x** (Tensor) - 用于计算GeLU函数的Tensor,数据类型为float16或float32。 | |||
| **输出:** | |||
| Tensor,数据类型和shape与 `x` 的相同。 | |||
| **异常:** | |||
| - **TypeError:** `x` 不是Tensor。 | |||
| - **TypeError:** `x` 的数据类型既不是float16也不是float32。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> x = Tensor(np.array([1.0, 2.0, 3.0]), mindspore.float32) | |||
| >>> gelu = ops.GeLU() | |||
| >>> result = gelu(x) | |||
| >>> print(result) | |||
| [0.841192 1.9545976 2.9963627] | |||
| @@ -0,0 +1,39 @@ | |||
| mindspore.ops.L2Loss | |||
| ==================== | |||
| .. py:class:: mindspore.ops.L2Loss(*args, **kwargs) | |||
| 计算Tensor的L2范数的一半,不对结果进行 `sqrt` 开方。 | |||
| 把 `input_x` 设为x,输出设为loss。 | |||
| .. math:: | |||
| loss = sum(x ** 2) / 2 | |||
| **输入:** | |||
| **input_x** (Tensor) - 用于计算L2范数的Tensor。数据类型必须为float16或float32。 | |||
| **输出:** | |||
| Tensor,具有与 `input_x` 相同的数据类型。输出Tensor是loss的值,是一个scalar Tensor。 | |||
| **异常:** | |||
| - **TypeError:** `input_x` 不是Tensor。 | |||
| - **TypeError:** `input_x` 的数据类型既不是float16也不是float32。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> input_x = Tensor(np.array([1, 2, 3]), mindspore.float16) | |||
| >>> l2_loss = ops.L2Loss() | |||
| >>> output = l2_loss(input_x) | |||
| >>> print(output) | |||
| 7.0 | |||
| @@ -0,0 +1,47 @@ | |||
| mindspore.ops.LessEqual | |||
| ======================== | |||
| .. py:class:: mindspore.ops.LessEqual(*args, **kwargs) | |||
| 按元素计算 :math:`x <= y` 的bool值。 | |||
| 输入 `x` 和 `y` 遵循隐式类型转换规则,使数据类型保持一致。 | |||
| 输入必须是两个Tensor,或一个Tensor和一个Scalar。 | |||
| 当输入是两个Tensor时,它们的数据类型不能同时是bool,它们的shape可以广播。 | |||
| 当输入是一个Tensor和一个Scalar时,Scalar只能是一个常数。 | |||
| .. math:: | |||
| out_{i} =\begin{cases} | |||
| & \text{True, if } x_{i}<=y_{i} \\ | |||
| & \text{False, if } x_{i}>y_{i} | |||
| \end{cases} | |||
| **输入:** | |||
| - **x** (Union[Tensor, Number, bool]) - 第一个输入,是一个Number、bool值或数据类型为Number或bool的Tensor。 | |||
| - **y** (Union[Tensor, Number, bool]) - 第二个输入,当第一个输入是Tensor时,第二个输入应该是一个Number或bool值,或数据类型为Number或bool的Tensor。 | |||
| **输出:** | |||
| Tensor,shape与广播后的shape相同,数据类型为bool。 | |||
| **异常:** | |||
| **TypeError:** `x` 和 `y` 都不是Tensor。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> x = Tensor(np.array([1, 2, 3]), mindspore.int32) | |||
| >>> y = Tensor(np.array([1, 1, 4]), mindspore.int32) | |||
| >>> less_equal = ops.LessEqual() | |||
| >>> output = less_equal(x, y) | |||
| >>> print(output) | |||
| [ True False True] | |||
| @@ -0,0 +1,40 @@ | |||
| mindspore.ops.Log | |||
| ================= | |||
| .. py:class:: mindspore.ops.Log(*args, **kwargs) | |||
| 按元素返回Tensor的自然对数。 | |||
| .. math:: | |||
| y_i = log_e(x_i) | |||
| .. warning:: | |||
| 如果算子Log的输入值在(0,0.01]或[0.95,1.05]范围内,则输出精度可能会发生变化。 | |||
| **输入:** | |||
| **x** (Tensor) - 输入Tensor。该值必须大于0。shape为 :math:`(N,*)`,其中 :math:`*` 表示任意的附加维度数,它的秩应小于8。 | |||
| **输出:** | |||
| Tensor,具有与 `x` 相同的shape。 | |||
| **异常:** | |||
| **TypeError:** `x` 不是Tensor。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> x = Tensor(np.array([1.0, 2.0, 4.0]), mindspore.float32) | |||
| >>> log = ops.Log() | |||
| >>> output = log(x) | |||
| >>> print(output) | |||
| [0. 0.6931472 1.3862944] | |||
| @@ -0,0 +1,48 @@ | |||
| mindspore.ops.matmul | |||
| ===================== | |||
| .. py:class:: mindspore.ops.MatMul(transpose_a=False, transpose_b=False) | |||
| 将矩阵 `a` 和矩阵 `b` 相乘。 | |||
| .. math:: | |||
| (Output)_{i j}=\sum_{k=1}^{p} a_{i k} b_{k j}=a_{i 1} b_{1 j}+a_{i 2} b_{2 j}+\cdots+a_{i p} b_{p j}, p\in N | |||
| 其中, :math:`i,j` 表示输出的第i行和第j列元素。 | |||
| **参数:** | |||
| - **transpose_a** (bool):如果为True,则在相乘之前转置 `a`。默认值:False。 | |||
| - **transpose_b** (bool):如果为True,则在相乘之前转置 `b`。默认值:False。 | |||
| **输入:** | |||
| - **a** (Tensor) - 要相乘的第一个Tensor。如果`transpose_a`为False,则该Tensor的shape为 :math:`(N, C)`;否则,该Tensor的shape为 :math:`(C, N)`。 | |||
| - **b** (Tensor) - 要相乘的第二个Tensor。如果`transpose_b`为False,则该Tensor的shape为 :math:`(C, M)`;否则,该Tensor的shape为 :math:`(M, C)`。 | |||
| **输出:** | |||
| Tensor,输出Tensor的shape为 :math:`(N, M)`。 | |||
| **异常:** | |||
| - **TypeError:** `transpose_a` 或 `transpose_b` 不是bool。 | |||
| - **ValueError:** 矩阵 `a` 的维度的列不等于矩阵 `b` 的维度的行。 | |||
| - **ValueError:** `a` 或 `b` 的维度不等于2。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> a = Tensor(np.ones(shape=[1, 3]), mindspore.float32) | |||
| >>> b = Tensor(np.ones(shape=[3, 4]), mindspore.float32) | |||
| >>> matmul = ops.MatMul() | |||
| >>> output = matmul(a, b) | |||
| >>> print(output) | |||
| [[3. 3. 3. 3.]] | |||
| @@ -0,0 +1,45 @@ | |||
| mindspore.ops.Mul | |||
| ================= | |||
| .. py:class:: mindspore.ops.Mul(*args, **kwargs) | |||
| 两个Tensor按元素相乘。 | |||
| 输入 `x` 和 `y` 遵循隐式类型转换规则,使数据类型保持一致。 | |||
| 输入必须是两个Tensor,或一个Tensor和一个Scalar。 | |||
| 当输入是两个Tensor时,它们的数据类型不能同时是bool,它们的shape可以广播。 | |||
| 当输入是一个Tensor和一个Scalar时,Scalar只能是一个常数。 | |||
| .. math:: | |||
| out_{i} = x_{i} * y_{i} | |||
| **输入:** | |||
| - **x** (Union[Tensor, Number, bool]) - 第一个输入,是一个Number、bool值或数据类型为Number或bool的Tensor。 | |||
| - **y** (Union[Tensor, Number, bool]) - 第二个输入,当第一个输入是Tensor时,第二个输入应该是一个Number或bool值,或数据类型为Number或bool的Tensor。 | |||
| **输出:** | |||
| Tensor,shape与广播后的shape相同,数据类型为两个输入中精度较高的类型。 | |||
| **异常:** | |||
| - **TypeError:** `x` 和 `y` 不是Tensor、Number或bool。 | |||
| - **ValueError:** `x` 和 `y` 的shape不相同。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> x = Tensor(np.array([1.0, 2.0, 3.0]), mindspore.float32) | |||
| >>> y = Tensor(np.array([4.0, 5.0, 6.0]), mindspore.float32) | |||
| >>> mul = ops.Mul() | |||
| >>> output = mul(x, y) | |||
| >>> print(output) | |||
| [ 4. 10. 18.] | |||
| @@ -0,0 +1,36 @@ | |||
| mindspore.ops.OnesLike | |||
| ====================== | |||
| .. py:class:: mindspore.ops.OnesLike(*args, **kwargs) | |||
| 创建新Tensor。所有元素的值都为1。 | |||
| 返回填充了Scalar值为1的具有与输入相同shape和数据类型的Tensor。 | |||
| **输入:** | |||
| **input_x** (Tensor) - 输入Tensor。shape为 :math:`(N,*)`,其中 :math:`*` 表示任意的附加维度数。 | |||
| **输出:** | |||
| Tensor,具有与 `input_x` 相同的shape和类型,并填充了1。 | |||
| **异常:** | |||
| **TypeError:** `input_x` 不是Tensor。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> oneslike = ops.OnesLike() | |||
| >>> input_x = Tensor(np.array([[0, 1], [2, 1]]).astype(np.int32)) | |||
| >>> output = oneslike(input_x) | |||
| >>> print(output) | |||
| [[1 1] | |||
| [1 1]] | |||
| @@ -0,0 +1,64 @@ | |||
| mindspore.ops.PReLU | |||
| =================== | |||
| .. py:class:: mindspore.ops.PReLU(*args, **kwargs) | |||
| 带参数的线性修正单元激活函数(Parametric Rectified Linear Unit activation function)。 | |||
| `Delving Deep into Rectifiers:Surpassing Human-Level Performance on ImageNet Classification <https://arxiv.org/abs/1502.01852>`_ 描述了PReLU激活函数。定义如下: | |||
| .. math:: | |||
| prelu(x_i)= \max(0, x_i) + \min(0, w * x_i), | |||
| 其中 :math:`x_i` 是输入的一个通道的一个元素,`w` 是通道权重。 | |||
| .. note:: | |||
| Ascend不支持0-D或1-D的x。 | |||
| **输入:** | |||
| - **x** (Tensor) - 用于计算激活函数的Tensor。数据类型为float16或float32。shape为 :math:`(N, C, *)`,其中 :math:`*` 表示任意的附加维度数。 | |||
| - **weight** (Tensor) - 权重Tensor。数据类型为float16或float32。只有两种shape是合法的,1或 `input_x` 的通道数。通道维度是输入的第二维。当输入为0-D或1-D Tensor时,通道数为1。 | |||
| **输出:** | |||
| Tensor,数据类型与 `x` 的相同。 | |||
| 有关详细信息,请参考:class:`nn.PReLU`。 | |||
| **异常:** | |||
| - **TypeError:** `x` 或 `weight` 的数据类型既不是float16也不是float32。 | |||
| - **TypeError:** `x` 或 `weight` 不是Tensor。 | |||
| - **ValueError:** `x` 是Ascend上的0-D或1-D Tensor。 | |||
| - **ValueError:** `weight` 不是1-D Tensor。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> class Net(nn.Cell): | |||
| ... def __init__(self): | |||
| ... super(Net, self).__init__() | |||
| ... self.prelu = ops.PReLU() | |||
| ... def construct(self, x, weight): | |||
| ... result = self.prelu(x, weight) | |||
| ... return result | |||
| ... | |||
| >>> x = Tensor(np.arange(-6, 6).reshape((2, 3, 2)), mindspore.float32) | |||
| >>> weight = Tensor(np.array([0.1, 0.6, -0.3]), mindspore.float32) | |||
| >>> net = Net() | |||
| >>> output = net(x, weight) | |||
| >>> print(output) | |||
| [[[-0.60 -0.50] | |||
| [-2.40 -1.80] | |||
| [ 0.60 0.30]] | |||
| [[ 0.00 1.00] | |||
| [ 2.00 3.00] | |||
| [ 4.0 5.00]]] | |||
| @@ -0,0 +1,52 @@ | |||
| mindspore.ops.Pow | |||
| ================== | |||
| .. py:class:: mindspore.ops.Pow(*args, **kwargs) | |||
| 计算`x`中每个元素的`y`的幂次。 | |||
| 输入 `x` 和 `y` 遵循隐式类型转换规则,使数据类型保持一致。 | |||
| 输入必须是两个Tensor,或一个Tensor和一个Scalar。 | |||
| 当输入是两个Tensor时,它们的数据类型不能同时是bool,它们的shape可以广播。 | |||
| 当输入是一个Tensor和一个Scalar时,Scalar只能是一个常数。 | |||
| .. math:: | |||
| out_{i} = x_{i} ^{ y_{i}} | |||
| **输入:** | |||
| - **x** (Union[Tensor, Number, bool]) - 第一个输入,是一个Number、bool值或数据类型为Number或bool的Tensor。 | |||
| - **y** (Union[Tensor, Number, bool]) - 第二个输入,当第一个输入是Tensor时,第二个输入应该是一个Number或bool值,或数据类型为Number或bool的Tensor。 | |||
| **输出:** | |||
| Tensor,shape与广播后的shape相同,数据类型为两个输入中精度较高的类型。 | |||
| **异常:** | |||
| - **TypeError:** `x` 和 `y` 不是Tensor、Number或bool。 | |||
| - **ValueError:** `x` 和 `y` 的shape不相同。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> x = Tensor(np.array([1.0, 2.0, 4.0]), mindspore.float32) | |||
| >>> y = 3.0 | |||
| >>> pow = ops.Pow() | |||
| >>> output = pow(x, y) | |||
| >>> print(output) | |||
| [ 1. 8. 64.] | |||
| >>> | |||
| >>> x = Tensor(np.array([1.0, 2.0, 4.0]), mindspore.float32) | |||
| >>> y = Tensor(np.array([2.0, 4.0, 3.0]), mindspore.float32) | |||
| >>> pow = ops.Pow() | |||
| >>> output = pow(x, y) | |||
| >>> print(output) | |||
| [ 1. 16. 64.] | |||
| @@ -0,0 +1,53 @@ | |||
| mindspore.ops.ReLUV2 | |||
| ==================== | |||
| .. py:class:: mindspore.ops.ReLUV2(*args, **kwargs) | |||
| 线性修正单元激活函数(Rectified Linear Unit activation function)。 | |||
| 按元素返回 :math:`\max(x,\ 0)`。特别说明,负数输出值会被修改为0,正数输出不受影响。 | |||
| .. math:: | |||
| \text{ReLU}(x) = (x)^+ = \max(0, x) | |||
| .. note:: | |||
| 与 `ReLu` 的区别在于该算子多输出一个mask,且算子的kernel与 `ReLu` 的不同。 | |||
| **输入:** | |||
| **input_x** (Tensor) - 输入Tensor必须是4-D Tensor。 | |||
| **输出:** | |||
| - **output** (Tensor) - 数据类型和shape与 `input_x` 的相同。 | |||
| - **mask** (Tensor) - 数据类型必须为uint8的Tensor。 | |||
| **异常:** | |||
| - **TypeError:** `input_x` 不是Tensor。 | |||
| - **ValueError:** `input_x` 的shape不是4-D。 | |||
| **支持平台:** | |||
| ``Ascend`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> input_x = Tensor(np.array([[[[1, -2], [-3, 4]], [[-5, 6], [7, -8]]]]), mindspore.float32) | |||
| >>> relu_v2 = ops.ReLUV2() | |||
| >>> output, mask= relu_v2(input_x) | |||
| >>> print(output) | |||
| [[[[1. 0.] | |||
| [0. 4.]] | |||
| [[0. 6.] | |||
| [7. 0.]]]] | |||
| >>> print(mask) | |||
| [[[[[1 0] | |||
| [2 0]] | |||
| [[2 0] | |||
| [1 0]]]]] | |||
| @@ -0,0 +1,38 @@ | |||
| mindspore.ops.Reshape | |||
| ====================== | |||
| .. py:class:: mindspore.ops.Reshape(*args, **kwargs) | |||
| 基于给定的shape,使用相同的值对输入Tensor进行reshape操作。 | |||
| `input_shape`最多只能有一个-1,在这种情况下,它可以从剩余的维度和输入的元素个数中推断出来。 | |||
| **输入:** | |||
| - **input_x** (Tensor) - Tensor的shape为 :math:`(x_1, x_2, ..., x_R)`。 | |||
| - **input_shape** (tuple[int]) - 输入tuple由多个整数构成,如 :math:`(y_1, y_2, ..., y_S)`。只支持常量值。 | |||
| **输出:** | |||
| Tensor,其shape为 :math:`(y_1, y_2, ..., y_S)`。 | |||
| **异常:** | |||
| **ValueError:** 给定的`input_shape`,如果它有几个-1,或者其元素的乘积小于或等于0,或者无法被输入Tensor的shape的乘积相除,或者与输入的数组大小不匹配。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> input_x = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]), mindspore.float32) | |||
| >>> reshape = ops.Reshape() | |||
| >>> output = reshape(input_x, (3, 2)) | |||
| >>> print(output) | |||
| [[-0.1 0.3] | |||
| [ 3.6 0.4] | |||
| [ 0.5 -3.2]] | |||
| @@ -0,0 +1,48 @@ | |||
| mindspore.ops.SeLU | |||
| ================== | |||
| .. py:class:: mindspore.ops.SeLU(*args, **kwargs) | |||
| 按元素计算输入Tensor的SeLU(scaled exponential Linear Unit)函数。 | |||
| 该激活函数定义为: | |||
| .. math:: | |||
| E_{i} = | |||
| scale * | |||
| \begin{cases} | |||
| x_{i}, &\text{if } x_{i} \geq 0; \cr | |||
| \text{alpha} * (\exp(x_i) - 1), &\text{otherwise.} | |||
| \end{cases} | |||
| 其中, :math:`alpha` 和 :math:`scale` 是预定义的常量( :math:`alpha=1.67326324` and :math:`scale=1.05070098`)。 | |||
| 更多详细信息,请参见 `Self-Normalizing Neural Networks <https://arxiv.org/abs/1706.02515>`_ 。 | |||
| **输入:** | |||
| **input_x** (Tensor) - shape为 :math:`(N, *)` 的Tensor,其中, :math:`*` 表示任意的附加维度数,数据类型为float16或float32。 | |||
| **输出:** | |||
| Tensor,数据类型和shape与 `input_x` 的相同。 | |||
| **支持平台:** | |||
| ``Ascend`` | |||
| **异常:** | |||
| **TypeError:** `input_x` 的数据类型既不是float16也不是float32。 | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> input_x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32) | |||
| >>> selu = ops.SeLU() | |||
| >>> output = selu(input_x) | |||
| >>> print(output) | |||
| [[-1.1113307 4.202804 -1.7575096] | |||
| [ 2.101402 -1.7462534 9.456309 ]] | |||
| @@ -0,0 +1,42 @@ | |||
| mindspore.ops.Sigmoid | |||
| ===================== | |||
| .. py:class:: mindspore.ops.Sigmoid(*args, **kwargs) | |||
| Sigmoid激活函数。 | |||
| 按元素计算输入的Sigmoid函数。Sigmoid函数定义为: | |||
| .. math:: | |||
| \text{sigmoid}(x_i) = \frac{1}{1 + \exp(-x_i)}, | |||
| 其中, :math:`x_i` 是输入Tensor的一个元素。 | |||
| **输入:** | |||
| **input_x** (Tensor) - shape为 :math:`(N, *)` 的tensor,其中, :math:`*` 表示任意的附加维度数,数据类型为float16或float32。 | |||
| **输出:** | |||
| Tensor,数据类型和shape与 `input_x` 的相同。 | |||
| **异常:** | |||
| - **TypeError:** `input_x` 的数据类型既不是float16也不是float32。 | |||
| - **TypeError:** `input_x` 不是Tensor。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> input_x = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32) | |||
| >>> sigmoid = ops.Sigmoid() | |||
| >>> output = sigmoid(input_x) | |||
| >>> print(output) | |||
| [0.7310586 0.880797 0.95257413 0.98201376 0.9933072 ] | |||
| @@ -0,0 +1,35 @@ | |||
| mindspore.ops.Size | |||
| ================== | |||
| .. py:class:: mindspore.ops.Size(*args, **kwargs) | |||
| 返回Tensor的大小。 | |||
| 返回一个整数Scalar,表示输入的元素大小,即Tensor中元素的总数。 | |||
| **输入:** | |||
| **input_x** (Tensor) - Tensor的shape为 :math:`(x_1, x_2, ..., x_R)`。数据类型为Number。 | |||
| **输出:** | |||
| 整数,表示 `input_x` 元素大小的Scalar。它的值为 :math:`size=x_1*x_2*...x_R`。 | |||
| **异常:** | |||
| **TypeError:** `input_x` 不是Tensor。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> input_x = Tensor(np.array([[2, 2], [2, 2]]), mindspore.float32) | |||
| >>> size = ops.Size() | |||
| >>> output = size(input_x) | |||
| >>> print(output) | |||
| 4 | |||
| @@ -0,0 +1,44 @@ | |||
| mindspore.ops.Sub | |||
| ================= | |||
| .. py:class:: mindspore.ops.Sub(*args, **kwargs) | |||
| 按元素用第一个输入Tensor减去第二个输入Tensor。 | |||
| 输入 `x` 和 `y` 遵循隐式类型转换规则,使数据类型保持一致。 | |||
| 输入必须是两个Tensor,或一个Tensor和一个Scalar。 | |||
| 当输入是两个Tensor时,它们的数据类型不能同时是bool,它们的shape可以广播。 | |||
| 当输入是一个Tensor和一个Scalar时,Scalar只能是一个常数。 | |||
| .. math:: | |||
| out_{i} = x_{i} - y_{i} | |||
| **输入:** | |||
| - **x** (Union[Tensor, Number, bool]) - 第一个输入,是一个Number、bool值或数据类型为Number或bool的Tensor。 | |||
| - **y** (Union[Tensor, Number, bool]) - 第二个输入,当第一个输入是Tensor时,第二个输入应该是一个Number或bool值,或数据类型为Number或bool的Tensor。 | |||
| **输出:** | |||
| Tensor,shape与广播后的shape相同,数据类型为两个输入中精度较高的类型。 | |||
| **异常:** | |||
| - **TypeError:** `x` 和 `y` 不是Tensor、Number或bool。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> x = Tensor(np.array([1, 2, 3]), mindspore.int32) | |||
| >>> y = Tensor(np.array([4, 5, 6]), mindspore.int32) | |||
| >>> sub = ops.Sub() | |||
| >>> output = sub(x, y) | |||
| >>> print(output) | |||
| [-3 -3 -3] | |||
| @@ -0,0 +1,64 @@ | |||
| mindspore.ops.Tile | |||
| =================== | |||
| .. py:class:: mindspore.ops.Tile(*args, **kwargs) | |||
| 按照给定的次数复制Tensor。 | |||
| 通过复制 `multiples` 次 `input_x` 来创建新的Tensor。输出Tensor的第i维度有 `input_x.shape[i] * multiples[i]` 个元素,并且 `input_x` 的值沿第i维度被复制 `multiples[i]` 次。 | |||
| .. note:: | |||
| `multiples` 的长度必须大于或等于 `input_x` 的维度。 | |||
| **输入:** | |||
| - **input_x** (Tensor) - 1-D或更高的Tensor。将输入Tensor的shape设置为 :math:`(x_1, x_2, ..., x_S)`。 | |||
| - **multiples** (tuple[int]) - 输入tuple由多个整数构成,如 :math:`(y_1, y_2, ..., y_S)`。`multiples` 的长度不能小于 `input_x` 的维度。只支持常量值。 | |||
| **输出:** | |||
| Tensor,具有与 `input_x` 相同的数据类型。假设 `multiples` 的长度为 `d` ,`input_x` 的维度为 `input_x.dim`。 | |||
| - 如果 `input_x.dim = d`: 将其相应位置的shape相乘,输出的shape为 :math:`(x_1*y_1, x_2*y_2, ..., x_S*y_S)`。 | |||
| - 如果 `input_x.dim < d`: 在 `input_x` 的shape的前面填充1,直到它们的长度一致。例如将 `input_x` 的shape设置为 :math:`(1, ..., x_1, ..., x_R, x_S)`,然后可以将其相应位置的shape相乘,输出的shape为 :math:`(1*y_1, ..., x_R*y_R, x_S*y_S)`。 | |||
| **异常:** | |||
| - **TypeError:** `multiples` 不是tuple或者其元素并非全部是int。 | |||
| - **ValueError:** `multiples` 的元素并非全部大于0。 | |||
| - **ValueError:** `multiples` 的长度小于 `input_x` 中的维度。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> tile = ops.Tile() | |||
| >>> input_x = Tensor(np.array([[1, 2], [3, 4]]), mindspore.float32) | |||
| >>> multiples = (2, 3) | |||
| >>> output = tile(input_x, multiples) | |||
| >>> print(output) | |||
| [[1. 2. 1. 2. 1. 2.] | |||
| [3. 4. 3. 4. 3. 4.] | |||
| [1. 2. 1. 2. 1. 2.] | |||
| [3. 4. 3. 4. 3. 4.]] | |||
| >>> multiples = (2, 3, 2) | |||
| >>> output = tile(input_x, multiples) | |||
| >>> print(output) | |||
| [[[1. 2. 1. 2.] | |||
| [3. 4. 3. 4.] | |||
| [1. 2. 1. 2.] | |||
| [3. 4. 3. 4.] | |||
| [1. 2. 1. 2.] | |||
| [3. 4. 3. 4.]] | |||
| [[1. 2. 1. 2.] | |||
| [3. 4. 3. 4.] | |||
| [1. 2. 1. 2.] | |||
| [3. 4. 3. 4.] | |||
| [1. 2. 1. 2.] | |||
| [3. 4. 3. 4.]]] | |||
| @@ -0,0 +1,41 @@ | |||
| mindspore.ops.UniformReal | |||
| ========================= | |||
| .. py:class:: mindspore.ops.UniformReal(seed=0, seed2=0) | |||
| 产生随机的浮点数i,均匀分布在[0,1)范围内。 | |||
| **参数:** | |||
| - **seed** (int):算子层的随机种子,用于生成随机数。必须是非负的。默认值:0。 | |||
| - **seed2** (int):全局的随机种子,和算子层的随机种子共同决定最终生成的随机数。必须是非负的。默认值:0。 | |||
| **输入:** | |||
| **shape** (tuple) - 待生成的随机Tensor的shape。只支持常量值。 | |||
| **输出:** | |||
| Tensor。它的shape为输入 `shape` 表示的值。数据类型为float32。 | |||
| **异常:** | |||
| - **TypeError:** `seed` 和 `seed2` 都不是int。 | |||
| - **TypeError:** `shape` 不是tuple。 | |||
| - **ValueError:** `shape` 不是常量值。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> shape = (2, 2) | |||
| >>> uniformreal = ops.UniformReal(seed=2) | |||
| >>> output = uniformreal(shape) | |||
| >>> result = output.shape | |||
| >>> print(result) | |||
| (2, 2) | |||
| @@ -0,0 +1,36 @@ | |||
| mindspore.ops.ZerosLike | |||
| ======================= | |||
| .. py:class:: mindspore.ops.ZerosLike(*args, **kwargs) | |||
| 创建新的Tensor。它的所有元素的值都为0。 | |||
| 返回具有与输入Tensor相同shape和数据类型的值为0的Tensor。 | |||
| **输入:** | |||
| **input_x** (Tensor) - 输入Tensor。数据类型为int32、int64、float16或float32。shape为 :math:`(N,*)`,其中 :math:`*` 表示任意的附加维度数。 | |||
| **输出:** | |||
| Tensor,具有与 `input_x` 相同的shape和数据类型,并填充了0。 | |||
| **异常:** | |||
| **TypeError:** `input_x` 不是Tensor。 | |||
| **支持平台:** | |||
| ``Ascend`` ``GPU`` ``CPU`` | |||
| **样例:** | |||
| .. code-block:: | |||
| >>> zeroslike = ops.ZerosLike() | |||
| >>> input_x = Tensor(np.array([[0, 1], [2, 1]]).astype(np.float32)) | |||
| >>> output = zeroslike(input_x) | |||
| >>> print(output) | |||
| [[0. 0.] | |||
| [0. 0.]] | |||