mindspore.ops.Map
- class mindspore.ops.Map(ops=None, reverse=False)[源代码]
Map will apply the set operation on input sequences.
Apply the operations to every element of the sequence.
- Parameters
ops (Union[MultitypeFuncGraph, None]) – ops is the operation to apply. If ops is None, the operations should be put in the first input of the instance. Default: None
reverse (bool) – The optimizer needs to be inverted in some scenarios to improve parallel performance, general users please ignore. Reverse is the flag to decide if apply the operation reversely. Only supported in graph mode. Default is False.
- Inputs:
args (Tuple[sequence]) - If ops is not None, all the inputs should be the same length sequences, and each row of the sequences. e.g. If the length of args is 2, and for i in length of each sequence (args[0][i], args[1][i]) will be the input of the operation.
If ops is None, the first input is the operation, and the other is inputs.
- Outputs:
Sequence, the sequence of output after applying the function. e.g. operation(args[0][i], args[1][i]).
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> from mindspore import dtype as mstype >>> from mindspore import Tensor, ops >>> from mindspore.ops import MultitypeFuncGraph, Map >>> tensor_list = (Tensor(1, mstype.float32), Tensor(2, mstype.float32), Tensor(3, mstype.float32)) >>> # square all the tensor in the list >>> >>> square = MultitypeFuncGraph('square') >>> @square.register("Tensor") ... def square_tensor(x): ... return ops.square(x) >>> >>> common_map = Map() >>> output = common_map(square, tensor_list) >>> print(output) (Tensor(shape=[], dtype=Float32, value= 1), Tensor(shape=[], dtype=Float32, value= 4), Tensor(shape=[], dtype=Float32, value= 9)) >>> square_map = Map(square, False) >>> output = square_map(tensor_list) >>> print(output) (Tensor(shape=[], dtype=Float32, value= 1), Tensor(shape=[], dtype=Float32, value= 4), Tensor(shape=[], dtype=Float32, value= 9))