本文簡要介紹python語言中 torch.zeros_like
的用法。
用法:
torch.zeros_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) → Tensor
input(Tensor) -
input
的大小將決定輸出張量的大小。dtype(
torch.dtype
, 可選的) -返回張量的所需數據類型。默認值:如果None
,則默認為input
的數據類型。layout(
torch.layout
, 可選的) -返回張量的所需布局。默認值:如果None
,則默認為input
的布局。device(
torch.device
, 可選的) -返回張量的所需設備。默認值:如果None
,則默認為input
的設備。requires_grad(bool,可選的) -如果 autograd 應該在返回的張量上記錄操作。默認值:
False
。memory_format(
torch.memory_format
, 可選的) -返回的張量所需的內存格式。默認值:torch.preserve_format
。
返回一個用標量值
0
填充的張量,其大小與input
相同。torch.zeros_like(input)
等同於torch.zeros(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)
。警告
從 0.4 開始,此函數不支持
out
關鍵字。作為替代方案,舊的torch.zeros_like(input, out=output)
等效於torch.zeros(input.size(), out=output)
。例子:
>>> input = torch.empty(2, 3) >>> torch.zeros_like(input) tensor([[ 0., 0., 0.], [ 0., 0., 0.]])
參數:
關鍵字參數:
相關用法
- Python PyTorch zeros_用法及代碼示例
- Python PyTorch zeros用法及代碼示例
- Python PyTorch zeta用法及代碼示例
- Python PyTorch frexp用法及代碼示例
- Python PyTorch jvp用法及代碼示例
- Python PyTorch cholesky用法及代碼示例
- Python PyTorch vdot用法及代碼示例
- Python PyTorch ELU用法及代碼示例
- Python PyTorch ScaledDotProduct.__init__用法及代碼示例
- Python PyTorch gumbel_softmax用法及代碼示例
- Python PyTorch get_tokenizer用法及代碼示例
- Python PyTorch saved_tensors_hooks用法及代碼示例
- Python PyTorch positive用法及代碼示例
- Python PyTorch renorm用法及代碼示例
- Python PyTorch AvgPool2d用法及代碼示例
- Python PyTorch MaxUnpool3d用法及代碼示例
- Python PyTorch Bernoulli用法及代碼示例
- Python PyTorch Tensor.unflatten用法及代碼示例
- Python PyTorch Sigmoid用法及代碼示例
- Python PyTorch Tensor.register_hook用法及代碼示例
- Python PyTorch ShardedEmbeddingBagCollection.named_parameters用法及代碼示例
- Python PyTorch sqrt用法及代碼示例
- Python PyTorch PackageImporter.id用法及代碼示例
- Python PyTorch column_stack用法及代碼示例
- Python PyTorch diag用法及代碼示例
注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torch.zeros_like。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。