mindspore.ops.Partial

class mindspore.ops.Partial[源代码]

生成偏函数的实例。通过给一般函数的部分参数提供初始值来衍生出有特定功能的新函数。

输入:
  • args (Union[FunctionType, Tensor]) - 需传入的函数及其对应的参数。

输出:

FunctionType,偏函数及其对应的参数。

支持平台:

Ascend GPU CPU

样例:

>>> from mindspore import Tensor
>>> import mindspore.ops as ops
>>> def show_input(x, y, z):
...     return x, y, z
>>> partial = ops.Partial()
>>> partial_show_input = partial(show_input, Tensor(1))
>>> output1 = partial_show_input(Tensor(2), Tensor(3))
>>> print(output1)
(Tensor(shape=[], dtype=Int64, value= 1), Tensor(shape=[], dtype=Int64, value= 2), Tensor(shape=[], dtype=Int64,
 value= 3))
>>> output2 = partial_show_input(Tensor(3), Tensor(4))
>>> print(output2)
(Tensor(shape=[], dtype=Int64, value= 1), Tensor(shape=[], dtype=Int64, value= 3), Tensor(shape=[], dtype=Int64,
 value= 4))