mindspore.tensor

mindspore.tensor(input_data=None, dtype=None, shape=None, init=None, const_arg=False, device=None)[source]

Create a new Tensor in Cell.construct() or a function decorated by @jit.

In graph mode, MindSpore would create a new Tensor object at runtime dynamically, based on the dtype argument.

Please refer to Creating and Using Tensor .

The difference from the Tensor class is that it adds an Annotation to indicate the type of the created Tensor, which prevents the generation of AnyType.

The arguments and return values are the same as those of the Tensor class. Also see: mindspore.Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore as ms
>>> from mindspore import jit, tensor
>>> @jit
... def func(x):
...    return tensor(x.asnumpy(), dtype=ms.float32)
>>> x = tensor([1, 2, 3])
>>> y = func(x)
>>> print(y)
[1. 2. 3.]