本文簡要介紹python語言中 torch.as_strided
的用法。
用法:
torch.as_strided(input, size, stride, storage_offset=0) → Tensor
使用指定的
size
、stride
和storage_offset
創建現有torch.Tensor
input
的視圖。警告
創建的張量的多個元素可能引用單個內存位置。因此,就地操作(尤其是矢量化的操作)可能會導致不正確的行為。如果您需要寫入張量,請先克隆它們。
許多返回張量視圖的 PyTorch 函數都是使用此函數在內部實現的。這些函數(例如
torch.Tensor.expand()
)更易於閱讀,因此更建議使用。例子:
>>> x = torch.randn(3, 3) >>> x tensor([[ 0.9039, 0.6291, 1.0795], [ 0.1586, 2.1939, -0.4900], [-0.1909, -0.7503, 1.9355]]) >>> t = torch.as_strided(x, (2, 2), (1, 2)) >>> t tensor([[0.9039, 1.0795], [0.6291, 0.1586]]) >>> t = torch.as_strided(x, (2, 2), (1, 2), 1) tensor([[0.6291, 0.1586], [1.0795, 2.1939]])
參數:
相關用法
- Python PyTorch as_tensor用法及代碼示例
- Python PyTorch assert_close用法及代碼示例
- Python PyTorch async_execution用法及代碼示例
- Python PyTorch asin用法及代碼示例
- Python PyTorch asinh用法及代碼示例
- Python PyTorch argsort用法及代碼示例
- Python PyTorch addmm用法及代碼示例
- Python PyTorch addmv用法及代碼示例
- Python PyTorch apply_effects_tensor用法及代碼示例
- Python PyTorch angle用法及代碼示例
- Python PyTorch all_reduce用法及代碼示例
- Python PyTorch atanh用法及代碼示例
- Python PyTorch annotate用法及代碼示例
- Python PyTorch argmax用法及代碼示例
- Python PyTorch atan用法及代碼示例
- Python PyTorch acos用法及代碼示例
- Python PyTorch all_gather用法及代碼示例
- Python PyTorch avg_pool1d用法及代碼示例
- Python PyTorch allreduce_hook用法及代碼示例
- Python PyTorch argmin用法及代碼示例
- Python PyTorch any用法及代碼示例
- Python PyTorch all_to_all用法及代碼示例
- Python PyTorch add用法及代碼示例
- Python PyTorch addcdiv用法及代碼示例
- Python PyTorch acosh用法及代碼示例
注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torch.as_strided。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。