mindspore.tensor

View Source On Gitee
mindspore.tensor(input_data=None, dtype=None, shape=None, init=None, internal=False, const_arg=False)[source]

Create a new Tensor in Cell.construct() or 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 between it and the Tensor class is that it adds Annotation which can prevent the generation of AnyType compared to the Tensor class.

The arguments and return values are the same as the Tensor class. Also see: mindspore.Tensor. internally to indicate the type of the Tensor currently being created,

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.]