mindspore/docs/api/api_python/ops/mindspore.ops.func_diff.rst

28 lines
1.7 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.ops.diff
==================
.. py:function:: mindspore.ops.diff(x, n=1, axis=-1, prepend=None, append=None)
沿着给定维度计算输入Tensor `x` 的n阶前向差分。
第一阶差分沿着给定 `axis` 由如下公式计算::math:`out[i] = a[i+1] - a[i]` ,更高阶差分通过将上一阶计算结果作为输入迭代调用 `diff` 计算。
.. note::
不支持空Tensor, 如果传入了空Tensor会出现ValueError。
参数:
- **x** (Tensor) - 输入Tensor。x元素的数据类型不支持uint16、uint32 或 uint64。
- **n** (int可选) - 递归计算差分的阶数目前只支持1。默认值1。
- **axis** (int可选) - 计算差分的维度,默认是最后一维。默认值:-1。
- **prepend** (Tensor可选) - 在计算差分之前,沿 axis 添加到 `x` 之前的值。它们的维度必须与输入的维度相同并且它们的shape必须与输入的shape匹配但 axis 除外。默认值None。
- **append** (Tensor可选) - 在计算差分之前,沿 axis 添加到 `x` 之后的值。它们的维度必须与输入的维度相同并且它们的shape必须与输入的shape匹配但 axis 除外。默认值None。
返回:
Tensor输入Tensor差分后的结果。输出的shape除了第 `axis` 维上尺寸缩小 `n` 以外,与 `x` 一致。输出的类型与 `x` 一致。
异常:
- **TypeError** - 如果 `x` 不是Tensor。
- **TypeError** - 如果 `x` 的元素的数据类型是uint16、uint32 或 uint64。
- **TypeError** - 如果 `x` 的维度小于1。
- **RuntimeError** - 如果 `n` 不是1。