mindspore.mint.empty_like
- mindspore.mint.empty_like(input, *, dtype=None, device=None)[源代码]
创建一个未初始化的Tesnor,shape和 input 相同,dtype由 dtype 决定,Tensor使用的内存由 device 决定。
警告
这是一个实验性API,后续可能修改或删除。
- 参数:
input (Tensor) - 任意维度的Tensor。
- 关键字参数:
dtype (
mindspore.dtype
, 可选) - 用来描述所创建的Tensor的 dtype 。如果为None
,那么将会使用 input 的dtype。默认值:None
。device (string, 可选) - 指定Tensor使用的内存来源。当前支持
CPU
和Ascend
。如果为None
, 那么将会使用input
的内存来源,如果input
没有申请内存,将会使用mindspore.set_device()
设置的值。 默认值None
。
- 返回:
Tensor,具有与 input 相同的shape,但是数据内容没有初始化(可能是任意值)。
- 异常:
TypeError - input 不是Tensor。
- 支持平台:
Ascend
样例:
>>> import mindspore >>> from mindspore import mint, Tensor >>> x = Tensor([[1, 2, 3], [4, 5, 6]]) >>> output1 = mint.empty_like(x) >>> print(output1) [[0 0 0] [0 0 0]] >>> output2 = mint.empty_like(x, dtype=mindspore.float64) >>> print(output2) [[0. 0. 0.] [0. 0. 0.]]