mindspore.ops.Print

class mindspore.ops.Print[source]

Outputs the tensor or string to stdout. The outputs are printed to screen by default. It can also be saved in a file by setting the parameter print_file_path in context. Once set, the output will be saved in the file specified by print_file_path. parse_print can be employed to reload the data. For more information, please refer to mindspore.context.set_context() and mindspore.parse_print().

Note

In pynative mode, please use python print function. In graph mode, the bool, int and float would be converted into Tensor to print, str remains unchanged. This function is used for debugging. When too much data is printed at the same time, in order not to affect the main process, the framework may discard some data. At this time, if you need to record the data completely, you can recommended to use the Summary function. Please check Summary.

Inputs:
  • input_x (Union[Tensor, bool, int, float, str]) - The graph node to attach to. Supports multiple inputs which are separated by ‘,’.

Outputs:

Tensor, has the same data type and shape as original input_x.

Raises

TypeError – If input_x is not one of the following: Tensor, bool, int, float, str.

Supported Platforms:

Ascend GPU

Examples

>>> class PrintDemo(nn.Cell):
...     def __init__(self):
...         super(PrintDemo, self).__init__()
...         self.print = ops.Print()
...
...     def construct(self, x, y):
...         self.print('Print Tensor x and Tensor y:', x, y)
...         return x
...
>>> x = Tensor(np.ones([2, 1]).astype(np.int32))
>>> y = Tensor(np.ones([2, 2]).astype(np.int32))
>>> net = PrintDemo()
>>> result = net(x, y)
Print Tensor x and Tensor y:
Tensor(shape=[2, 1], dtype=Int32, value=
[[1]
 [1]])
Tensor(shape=[2, 2], dtype=Int32, value=
[[1 1]
 [1 1]])