torch.empty#
- torch.empty(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False, memory_format=torch.contiguous_format) Tensor#
返回一個包含未初始化資料的張量。張量的形狀由可變引數
size定義。注意
如果
torch.use_deterministic_algorithms()和torch.utils.deterministic.fill_uninitialized_memory都設定為True,則輸出張量會被初始化,以防止使用資料作為操作輸入的任何可能的非確定性行為。浮點數和複數張量將填充 NaN,整數張量將填充最大值。- 引數
size (int...) – 定義輸出張量形狀的整數序列。可以是可變數量的引數,也可以是列表或元組之類的集合。
- 關鍵字引數
out (Tensor, optional) – 輸出張量。
dtype (
torch.dtype, optional) – 返回張量的期望資料型別。預設值:如果None,則使用全域性預設值(參見torch.set_default_dtype())。layout (
torch.layout, 可選) – 返回張量的所需佈局。預設:torch.strided。device (
torch.device, 可選) – 返回張量的所需裝置。預設:如果為None,則使用當前裝置作為預設張量型別(參見torch.set_default_device())。對於 CPU 張量型別,device將是 CPU;對於 CUDA 張量型別,device將是當前的 CUDA 裝置。requires_grad (bool, optional) – 如果 autograd 應記錄在返回的張量上的操作。預設值:
False。pin_memory (bool, optional) – 如果設定為 True,則返回的張量將被分配到固定記憶體中。僅適用於 CPU 張量。預設值:
False。memory_format (
torch.memory_format, optional) – 返回張量的所需記憶體格式。預設值:torch.contiguous_format。
示例
>>> torch.empty((2,3), dtype=torch.int64) tensor([[ 9.4064e+13, 2.8000e+01, 9.3493e+13], [ 7.5751e+18, 7.1428e+18, 7.5955e+18]])