指点成金-最美分享吧

登录

pytorch torch.empty()函数(返回填充有未初始化数据的张量。 张量的形状由可变的参数大小定义)

佚名 举报

篇首语:本文由小编为大家整理,主要介绍了pytorch torch.empty()函数(返回填充有未初始化数据的张量。 张量的形状由可变的参数大小定义)相关的知识,希望对你有一定的参考价值。

from https://pytorch.org/docs/1.1.0/torch.html#torch.empty

torch.empty(*sizes, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) → TensorReturns a tensor filled with uninitialized data. The shape of the tensor is defined by the variable argument sizes.返回填充有未初始化数据的张量。 张量的形状由可变的参数大小定义。

Parameters

sizes (int...) – a sequence of integers defining the shape of the output tensor. Can be a variable number of arguments or a collection like a list or tuple.定义输出张量形状的整数序列。 可以是可变数量的参数,也可以是列表或元组之类的集合。out (Tensor, optional) – the output tensor 输出张量dtype (torch.dtype, optional) – the desired data type of returned tensor. Default: if None, uses a global default (see torch.set_default_tensor_type()).返回张量的所需数据类型。 默认值:如果为None,则使用全局默认值(请参阅torch.set_default_tensor_type())。layout (torch.layout, optional) – the desired layout of returned Tensor. Default: torch.strided.返回的Tensor的所需布局。 默认值:torch.strided。device (torch.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.返回张量的所需设备。 默认值:如果为None,则使用当前设备作为默认张量类型(请参见torch.set_default_tensor_type())。 对于CPU张量类型,设备将是CPU;对于CUDA张量类型,设备将是当前CUDA设备。requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.如果autograd应该在返回的张量上记录操作。 默认值:False。pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False.如果设置,返回的张量将在固定的内存中分配。 仅适用于CPU张量。 默认值:False

example

>>> torch.empty(2, 3)tensor(1.00000e-08 *       [[ 6.3984,  0.0000,  0.0000],        [ 0.0000,  0.0000,  0.0000]])

以上是关于pytorch torch.empty()函数(返回填充有未初始化数据的张量。 张量的形状由可变的参数大小定义)的主要内容,如果未能解决你的问题,请参考以下文章