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

28 lines
1.7 KiB
ReStructuredText
Raw Permalink Normal View History

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