mindspore.Tensor.astype ======================= .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg :target: https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python/mindspore/Tensor/mindspore.Tensor.astype.rst :alt: 查看源文件 .. py:method:: mindspore.Tensor.astype(dtype, copy=True) 将Tensor转为指定数据类型,可指定是否返回副本。 参数: - **dtype** (Union[mindspore.dtype, numpy.dtype, str]) - 指定的Tensor数据类型,可以是: `mindspore.dtype.float32` , `numpy.float32` 或 `float32` 的格式。 - **copy** (bool, 可选) - 默认情况下,astype返回新拷贝的Tensor。如果该参数设为 ``False`` ,则返回输入Tensor而不是副本。默认值: ``True`` 。 返回: Tensor,指定数据类型的Tensor。 异常: - **TypeError** - 指定了无法解析的类型。