sciai.utils.to_tensor

View Source On Gitee
sciai.utils.to_tensor(tensors, dtype=ms.float32)[source]

Cast array(ies)/tensor(s) to a given MindSpore data type.

Parameters
  • tensors (Union[Tensor, ndarray, Number, np.floating, tuple[Tensor, ndarray]]) – Tensor(s) to cast.

  • dtype (type) – MindSpore Tensor data type. Default: ms.float32.

Returns

Union(Tensor, tuple(Tensor)), Single one or tuple of cast tensor(s).

Raises

TypeError – If input types are not correct.

Examples

>>> import numpy as np
>>> from sciai.utils import to_tensor
>>> tensors = to_tensor((np.array([1]), np.array([2])))
>>> print(tensors)
(Tensor(shape=[1], dtype=Float32, value= [ 1.00000000e+00]),
Tensor(shape=[1], dtype=Float32, value= [ 2.00000000e+00]))
>>> print(tensors[0].dtype)
Float32