diff --git a/docs/1.4/77.md b/docs/1.4/77.md index 72b2f5dfa25f7c90d4498420e8ddac176419d8c6..e5412797e56bb38e2394bcdc2b5a16828b9e5a4f 100644 --- a/docs/1.4/77.md +++ b/docs/1.4/77.md @@ -4,25 +4,9 @@ [`torch.Tensor`](#torch.Tensor "torch.Tensor") 是包含单个数据类型元素的多维矩阵。 -torch定义了 9 种 CPU 张量类型和 9 种 GPU 张量类型: +Torch 定义了 9 种 CPU 张量类型和 9 种 GPU 张量类型: -| - -数据类型 - - | - -dtype - - | - -CPU 张量 - - | - -GPU 张量 - - | +| 数据类型 | dtype | CPU 张量 | GPU 张量 | | --- | --- | --- | --- | | 32 位浮点 | `torch.float32`或`torch.float` | `torch.FloatTensor` | `torch.cuda.FloatTensor` | | 64 位浮点 | `torch.float64`或`torch.double` | `torch.DoubleTensor` | `torch.cuda.DoubleTensor` | @@ -112,22 +96,22 @@ tensor([[ 2.0000, -2.0000], 有关 [`torch.Tensor`](#torch.Tensor "torch.Tensor") 的 [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") , [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") 和 [`torch.layout`](tensor_attributes.html#torch.torch.layout "torch.torch.layout") 属性的更多信息,请参阅[ [Tensor Attributes](tensor_attributes.html#tensor-attributes-doc) 。 -Note +注意 改变张量的方法用下划线后缀标记。 例如,`torch.FloatTensor.abs_()`在原位计算绝对值并返回修改后的张量,而`torch.FloatTensor.abs()`在新张量中计算结果。 -Note +注意 要更改现有张量的 [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") 和/或 [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") ,请考虑在张量上使用 [`to()`](#torch.Tensor.to "torch.Tensor.to") 方法。 -Warning +警告 [`torch.Tensor`](#torch.Tensor "torch.Tensor") 的当前实现引入了内存开销,因此,在具有许多微小张量的应用程序中,它可能导致意外的高内存使用率。 如果是这种情况,请考虑使用一种大型结构。 * * * ``` -class torch.Tensor¶ +class torch.Tensor ``` 根据您的用例,创建张量的主要方法有几种。 @@ -143,28 +127,28 @@ class torch.Tensor¶ * * * ``` -new_tensor(data, dtype=None, device=None, requires_grad=False) → Tensor¶ +new_tensor(data, dtype=None, device=None, requires_grad=False) → Tensor ``` 返回以`data`作为张量数据的新张量。 默认情况下,返回的张量与此张量具有相同的 [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") 和 [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") 。 -Warning +警告 [`new_tensor()`](#torch.Tensor.new_tensor "torch.Tensor.new_tensor") 始终复制`data`。 如果您有张量`data`并希望避免复制,请使用 [`torch.Tensor.requires_grad_()`](#torch.Tensor.requires_grad_ "torch.Tensor.requires_grad_") 或 [`torch.Tensor.detach()`](autograd.html#torch.Tensor.detach "torch.Tensor.detach") 。 如果您有一个 numpy 数组并且想要避免复制,请使用 [`torch.from_numpy()`](torch.html#torch.from_numpy "torch.from_numpy") 。 -Warning +警告 -当数据是张量 <cite>x</cite> 时, [`new_tensor()`](#torch.Tensor.new_tensor "torch.Tensor.new_tensor") 从传递的任何数据中读出“数据”,并构造一个叶子变量。 因此,`tensor.new_tensor(x)`等同于`x.clone().detach()`,`tensor.new_tensor(x, requires_grad=True)`等同于`x.clone().detach().requires_grad_(True)`。 建议使用`clone()`和`detach()`的等效项。 +当数据是张量 _x_ 时, [`new_tensor()`](#torch.Tensor.new_tensor "torch.Tensor.new_tensor") 从传递的任何数据中读出“数据”,并构造一个叶子变量。 因此,`tensor.new_tensor(x)`等同于`x.clone().detach()`,`tensor.new_tensor(x, requires_grad=True)`等同于`x.clone().detach().requires_grad_(True)`。 建议使用`clone()`和`detach()`的等效项。 参数 -* **数据** (_array_like_ )–返回的张量副本`data`。 +* **data** (_array_like_ )–返回的张量副本`data`。 -* **dtype** ([`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") ,可选)–返回张量的所需类型。 默认值:如果为 None,则与此张量相同的 [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") 。 +* **dtype** ([`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") ,可选)– 返回张量的所需类型。 默认值:如果为 None,则与此张量相同的 [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") 。 -* **设备** ([`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") ,可选)–返回张量的所需设备。 默认值:如果为 None,则与此张量相同的 [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") 。 +* **device** ([`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") ,可选)– 返回张量的所需设备。 默认值:如果为 None,则与此张量相同的 [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") 。 -* **require_grad** (_bool_ _,_ _可选_)–如果 autograd 应该在返回的张量上记录操作。 默认值:`False`。 +* **require_grad** (_bool_ _,_ _可选_)– 返回的张量是否需要自动求导。 默认值:`False`。 例: @@ -180,22 +164,22 @@ tensor([[ 0, 1], * * * ``` -new_full(size, fill_value, dtype=None, device=None, requires_grad=False) → Tensor¶ +new_full(size, fill_value, dtype=None, device=None, requires_grad=False) → Tensor ``` 返回大小为 [`size`](#torch.Tensor.size "torch.Tensor.size") 的张量,并用`fill_value`填充。 默认情况下,返回的张量与此张量具有相同的 [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") 和 [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") 。 -Parameters +参数 * **fill_value** (_标量_)–用来填充输出张量的数字。 -* **dtype** ([`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype"), optional) – the desired type of returned tensor. Default: if None, same [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") as this tensor. +* **dtype** ([`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype"), optional) – 返回张量的所需类型。 默认值:如果为 None,则与此张量相同的 [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") 。 -* **device** ([`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device"), optional) – the desired device of returned tensor. Default: if None, same [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") as this tensor. +* **device** ([`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device"), optional) – 返回张量的所需设备。 默认值:如果为 None,则与此张量相同的 [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") 。 -* **requires_grad** (_bool__,_ _optional_) – If autograd should record operations on the returned tensor. Default: `False`. +* **requires_grad** (_bool__,_ _optional_) – 返回的张量是否需要自动求导。 默认值:`False`。 -Example: +例: ``` >>> tensor = torch.ones((2,), dtype=torch.float64) @@ -209,20 +193,20 @@ tensor([[ 3.1416, 3.1416, 3.1416, 3.1416], * * * ``` -new_empty(size, dtype=None, device=None, requires_grad=False) → Tensor¶ +new_empty(size, dtype=None, device=None, requires_grad=False) → Tensor ``` 返回大小为 [`size`](#torch.Tensor.size "torch.Tensor.size") 的张量,其中填充了未初始化的数据。 默认情况下,返回的张量具有与此张量相同的 [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") 和 [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") 。 -Parameters +参数 -* **dtype** ([`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype"), optional) – the desired type of returned tensor. Default: if None, same [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") as this tensor. +* **dtype** ([`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype"), optional) – -* **device** ([`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device"), optional) – the desired device of returned tensor. Default: if None, same [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") as this tensor. +* **device** ([`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device"), optional) – 返回张量的所需设备。 默认值:如果为 None,则与此张量相同的 [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") 。 -* **requires_grad** (_bool__,_ _optional_) – If autograd should record operations on the returned tensor. Default: `False`. +* **requires_grad** (_bool__,_ _optional_) – 返回的张量是否需要自动求导。 默认值:`False`。 -Example: +例: ``` >>> tensor = torch.ones(()) @@ -235,22 +219,22 @@ tensor([[ 5.8182e-18, 4.5765e-41, -1.0545e+30], * * * ``` -new_ones(size, dtype=None, device=None, requires_grad=False) → Tensor¶ +new_ones(size, dtype=None, device=None, requires_grad=False) → Tensor ``` 返回大小为 [`size`](#torch.Tensor.size "torch.Tensor.size") 的张量,并用`1`填充。 默认情况下,返回的张量与此张量具有相同的 [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") 和 [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") 。 -Parameters +参数 * **大小** (_python:int ..._ )–定义输出张量形状的整数列表,元组或`torch.Size`。 -* **dtype** ([`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype"), optional) – the desired type of returned tensor. Default: if None, same [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") as this tensor. +* **dtype** ([`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype"), optional) – 返回张量的所需类型。 默认: 如果是 None, 和 [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") 一样 -* **device** ([`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device"), optional) – the desired device of returned tensor. Default: if None, same [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") as this tensor. +* **device** ([`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device"), optional) – 返回张量所在的设备。 默认: 如果是 None, 和 [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") 一样 -* **requires_grad** (_bool__,_ _optional_) – If autograd should record operations on the returned tensor. Default: `False`. +* **requires_grad** (_bool__,_ _optional_) – 返回的张量是否需要自动求导。 默认值:`False`。 -Example: +例: ``` >>> tensor = torch.tensor((), dtype=torch.int32) @@ -263,22 +247,22 @@ tensor([[ 1, 1, 1], * * * ``` -new_zeros(size, dtype=None, device=None, requires_grad=False) → Tensor¶ +new_zeros(size, dtype=None, device=None, requires_grad=False) → Tensor ``` 返回大小为 [`size`](#torch.Tensor.size "torch.Tensor.size") 的张量,并用`0`填充。 默认情况下,返回的张量与此张量具有相同的 [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") 和 [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") 。 -Parameters +参数 * **size** (_python:int..._) – a list, tuple, or `torch.Size` of integers defining the shape of the output tensor. -* **dtype** ([`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype"), optional) – the desired type of returned tensor. Default: if None, same [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") as this tensor. +* **dtype** ([`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype"), optional) – 返回张量的所需类型。 默认值:如果为 None,则与此张量相同的 [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") 。 -* **device** ([`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device"), optional) – the desired device of returned tensor. Default: if None, same [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") as this tensor. +* **device** ([`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device"), optional) – 返回张量的所需设备。 默认值:如果为 None,则与此张量相同的 [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") 。 -* **requires_grad** (_bool__,_ _optional_) – If autograd should record operations on the returned tensor. Default: `False`. +* **requires_grad** (_bool__,_ _optional_) – 返回的张量是否需要自动求导。 默认值:`False`。 -Example: +例: ``` >>> tensor = torch.tensor((), dtype=torch.float64) @@ -289,13 +273,13 @@ tensor([[ 0., 0., 0.], ``` ``` -is_cuda¶ +is_cuda ``` 如果张量存储在 GPU 上,则为`True`,否则为`False`。 ``` -device¶ +device ``` 张量所在的 [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") 。 @@ -304,16 +288,16 @@ device¶ grad ``` -此属性默认为`None`,并在首次调用 [`backward()`](autograd.html#torch.Tensor.backward "torch.Tensor.backward") 计算`self`的梯度时成为张量。 然后,该属性将包含计算出的梯度,将来对 [`backward()`](autograd.html#torch.Tensor.backward "torch.Tensor.backward") 的调用将在其中累积(添加)梯度。 +此属性默认为`None`,并在首次调用 [`backward()`](autograd.html#torch.Tensor.backward "torch.Tensor.backward") 计算`self`的梯度时成为张量。 然后,该属性将包含计算出的梯度以及 [`backward()`](autograd.html#torch.Tensor.backward "torch.Tensor.backward")返回的梯度值,然后进行梯度累加。 ``` -ndim¶ +ndim ``` [`dim()`](#torch.Tensor.dim "torch.Tensor.dim") 的别名 ``` -T¶ +T ``` 这个张量的尺寸是否颠倒了吗? @@ -323,7 +307,7 @@ T¶ * * * ``` -abs() → Tensor¶ +abs() → Tensor ``` 参见 [`torch.abs()`](torch.html#torch.abs "torch.abs") @@ -331,7 +315,7 @@ abs() → Tensor¶ * * * ``` -abs_() → Tensor¶ +abs_() → Tensor ``` 就地版本的 [`abs()`](#torch.Tensor.abs "torch.Tensor.abs") @@ -339,7 +323,7 @@ abs_() → Tensor¶ * * * ``` -acos() → Tensor¶ +acos() → Tensor ``` 参见 [`torch.acos()`](torch.html#torch.acos "torch.acos") @@ -347,7 +331,7 @@ acos() → Tensor¶ * * * ``` -acos_() → Tensor¶ +acos_() → Tensor ``` 就地版本的 [`acos()`](#torch.Tensor.acos "torch.Tensor.acos") @@ -355,7 +339,7 @@ acos_() → Tensor¶ * * * ``` -add(value) → Tensor¶ +add(value) → Tensor ``` add(value = 1,other)->张量 @@ -365,7 +349,7 @@ add(value = 1,other)->张量 * * * ``` -add_(value) → Tensor¶ +add_(value) → Tensor ``` add_(value = 1,other)->张量 @@ -375,7 +359,7 @@ add_(value = 1,other)->张量 * * * ``` -addbmm(beta=1, alpha=1, batch1, batch2) → Tensor¶ +addbmm(beta=1, alpha=1, batch1, batch2) → Tensor ``` 参见 [`torch.addbmm()`](torch.html#torch.addbmm "torch.addbmm") @@ -383,7 +367,7 @@ addbmm(beta=1, alpha=1, batch1, batch2) → Tensor¶ * * * ``` -addbmm_(beta=1, alpha=1, batch1, batch2) → Tensor¶ +addbmm_(beta=1, alpha=1, batch1, batch2) → Tensor ``` 就地版本的 [`addbmm()`](#torch.Tensor.addbmm "torch.Tensor.addbmm") @@ -391,7 +375,7 @@ addbmm_(beta=1, alpha=1, batch1, batch2) → Tensor¶ * * * ``` -addcdiv(value=1, tensor1, tensor2) → Tensor¶ +addcdiv(value=1, tensor1, tensor2) → Tensor ``` 参见 [`torch.addcdiv()`](torch.html#torch.addcdiv "torch.addcdiv") @@ -399,7 +383,7 @@ addcdiv(value=1, tensor1, tensor2) → Tensor¶ * * * ``` -addcdiv_(value=1, tensor1, tensor2) → Tensor¶ +addcdiv_(value=1, tensor1, tensor2) → Tensor ``` 就地版本的 [`addcdiv()`](#torch.Tensor.addcdiv "torch.Tensor.addcdiv") @@ -407,7 +391,7 @@ addcdiv_(value=1, tensor1, tensor2) → Tensor¶ * * * ``` -addcmul(value=1, tensor1, tensor2) → Tensor¶ +addcmul(value=1, tensor1, tensor2) → Tensor ``` 参见 [`torch.addcmul()`](torch.html#torch.addcmul "torch.addcmul") @@ -415,7 +399,7 @@ addcmul(value=1, tensor1, tensor2) → Tensor¶ * * * ``` -addcmul_(value=1, tensor1, tensor2) → Tensor¶ +addcmul_(value=1, tensor1, tensor2) → Tensor ``` 就地版本的 [`addcmul()`](#torch.Tensor.addcmul "torch.Tensor.addcmul") @@ -423,7 +407,7 @@ addcmul_(value=1, tensor1, tensor2) → Tensor¶ * * * ``` -addmm(beta=1, alpha=1, mat1, mat2) → Tensor¶ +addmm(beta=1, alpha=1, mat1, mat2) → Tensor ``` 参见 [`torch.addmm()`](torch.html#torch.addmm "torch.addmm") @@ -431,7 +415,7 @@ addmm(beta=1, alpha=1, mat1, mat2) → Tensor¶ * * * ``` -addmm_(beta=1, alpha=1, mat1, mat2) → Tensor¶ +addmm_(beta=1, alpha=1, mat1, mat2) → Tensor ``` 就地版本的 [`addmm()`](#torch.Tensor.addmm "torch.Tensor.addmm") @@ -439,7 +423,7 @@ addmm_(beta=1, alpha=1, mat1, mat2) → Tensor¶ * * * ``` -addmv(beta=1, alpha=1, mat, vec) → Tensor¶ +addmv(beta=1, alpha=1, mat, vec) → Tensor ``` 参见 [`torch.addmv()`](torch.html#torch.addmv "torch.addmv") @@ -447,7 +431,7 @@ addmv(beta=1, alpha=1, mat, vec) → Tensor¶ * * * ``` -addmv_(beta=1, alpha=1, mat, vec) → Tensor¶ +addmv_(beta=1, alpha=1, mat, vec) → Tensor ``` 就地版本的 [`addmv()`](#torch.Tensor.addmv "torch.Tensor.addmv") @@ -455,7 +439,7 @@ addmv_(beta=1, alpha=1, mat, vec) → Tensor¶ * * * ``` -addr(beta=1, alpha=1, vec1, vec2) → Tensor¶ +addr(beta=1, alpha=1, vec1, vec2) → Tensor ``` 参见 [`torch.addr()`](torch.html#torch.addr "torch.addr") @@ -463,7 +447,7 @@ addr(beta=1, alpha=1, vec1, vec2) → Tensor¶ * * * ``` -addr_(beta=1, alpha=1, vec1, vec2) → Tensor¶ +addr_(beta=1, alpha=1, vec1, vec2) → Tensor ``` 就地版本的 [`addr()`](#torch.Tensor.addr "torch.Tensor.addr") @@ -471,7 +455,7 @@ addr_(beta=1, alpha=1, vec1, vec2) → Tensor¶ * * * ``` -allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) → Tensor¶ +allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) → Tensor ``` 参见 [`torch.allclose()`](torch.html#torch.allclose "torch.allclose") @@ -479,7 +463,7 @@ allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) → Tensor¶ * * * ``` -angle() → Tensor¶ +angle() → Tensor ``` 参见 [`torch.angle()`](torch.html#torch.angle "torch.angle") @@ -487,19 +471,19 @@ angle() → Tensor¶ * * * ``` -apply_(callable) → Tensor¶ +apply_(callable) → Tensor ``` 将函数`callable`应用于张量中的每个元素,并用`callable`返回的值替换每个元素。 -Note +注意 此功能仅适用于 CPU 张量,不应在需要高性能的代码段中使用。 * * * ``` -argmax(dim=None, keepdim=False) → LongTensor¶ +argmax(dim=None, keepdim=False) → LongTensor ``` 参见 [`torch.argmax()`](torch.html#torch.argmax "torch.argmax") @@ -507,7 +491,7 @@ argmax(dim=None, keepdim=False) → LongTensor¶ * * * ``` -argmin(dim=None, keepdim=False) → LongTensor¶ +argmin(dim=None, keepdim=False) → LongTensor ``` 参见 [`torch.argmin()`](torch.html#torch.argmin "torch.argmin") @@ -515,15 +499,15 @@ argmin(dim=None, keepdim=False) → LongTensor¶ * * * ``` -argsort(dim=-1, descending=False) → LongTensor¶ +argsort(dim=-1, descending=False) → LongTensor ``` -见:func: <cite>torch.argsort</cite> +参见:func: <cite>torch.argsort</cite> * * * ``` -asin() → Tensor¶ +asin() → Tensor ``` 参见 [`torch.asin()`](torch.html#torch.asin "torch.asin") @@ -531,7 +515,7 @@ asin() → Tensor¶ * * * ``` -asin_() → Tensor¶ +asin_() → Tensor ``` 就地版本的 [`asin()`](#torch.Tensor.asin "torch.Tensor.asin") @@ -539,7 +523,7 @@ asin_() → Tensor¶ * * * ``` -as_strided(size, stride, storage_offset=0) → Tensor¶ +as_strided(size, stride, storage_offset=0) → Tensor ``` 参见 [`torch.as_strided()`](torch.html#torch.as_strided "torch.as_strided") @@ -547,7 +531,7 @@ as_strided(size, stride, storage_offset=0) → Tensor¶ * * * ``` -atan() → Tensor¶ +atan() → Tensor ``` 参见 [`torch.atan()`](torch.html#torch.atan "torch.atan") @@ -555,7 +539,7 @@ atan() → Tensor¶ * * * ``` -atan2(other) → Tensor¶ +atan2(other) → Tensor ``` 参见 [`torch.atan2()`](torch.html#torch.atan2 "torch.atan2") @@ -563,7 +547,7 @@ atan2(other) → Tensor¶ * * * ``` -atan2_(other) → Tensor¶ +atan2_(other) → Tensor ``` 就地版本的 [`atan2()`](#torch.Tensor.atan2 "torch.Tensor.atan2") @@ -571,7 +555,7 @@ atan2_(other) → Tensor¶ * * * ``` -atan_() → Tensor¶ +atan_() → Tensor ``` 就地版本的 [`atan()`](#torch.Tensor.atan "torch.Tensor.atan") @@ -582,24 +566,24 @@ atan_() → Tensor¶ backward(gradient=None, retain_graph=None, create_graph=False) ``` -计算电流张量 w.r.t. 图叶。 +计算当前张量的梯度 w.r.t. 图叶。 -该图使用链规则进行区分。 如果张量是非标量的(即其数据具有多个元素)并且需要梯度,则该函数还需要指定`gradient`。 它应该是匹配类型和位置的张量,其中包含微分函数 w.r.t 的梯度。 `self`。 +该图使用链式法则进行区分。 如果张量是非标量的(即其数据具有多个元素)并且需要梯度,则该函数还需要指定`gradient`。 它应该是匹配类型和位置的张量,其中包含微分函数 w.r.t 的梯度。 `self`。 -此函数在树叶中累积渐变-调用它之前可能需要将它们归零。 +此函数是叶子梯度累加-调用它之前可能需要将它们归零。 -Parameters +参数 -* **梯度** ([_tensor_](#torch.Tensor "torch.Tensor") _或_ _无_)–梯度 w.r.t. 张量。 如果它是张量,除非`create_graph`为 True,否则它将自动转换为不需要 grad 的张量。 无法为标量张量或不需要等级的张量指定任何值。 如果 None 值可以接受,那么此参数是可选的。 +* **gradient** ([_tensor_](#torch.Tensor "torch.Tensor") _Tensor_ _None_)– 梯度 w.r.t. 张量。 如果它是张量,除非`create_graph`为 True,否则它将自动转换为不需要 grad 的张量。 无法为标量张量或不需要等级的张量指定任何值。 如果 None 值可以接受,那么此参数是可选的。 -* **keep_graph** (_bool_ _,_ _可选_)–如果`False`,则用于计算等级的图形将被释放。 请注意,几乎在所有情况下都不需要将此选项设置为 True,并且通常可以以更有效的方式解决它。 默认为`create_graph`的值。 +* **retian_graph** (_bool_ _,_ _可选_)– 如果`False`,则用于计算等级的图形将被释放。 请注意,几乎在所有情况下都不需要将此选项设置为 True,并且通常可以以更有效的方式解决它。 默认为`create_graph`的值。 -* **create_graph** (_bool_ _,_ _可选_)–如果`True`,则将构造导数图,从而允许计算高阶导数 产品。 默认为`False`。 +* **create_graph** (_bool_ _,_ _可选_)– 如果`True`,则将构造导数图,从而允许计算高阶导数产品。 默认为`False`。 * * * ``` -baddbmm(beta=1, alpha=1, batch1, batch2) → Tensor¶ +baddbmm(beta=1, alpha=1, batch1, batch2) → Tensor ``` 参见 [`torch.baddbmm()`](torch.html#torch.baddbmm "torch.baddbmm") @@ -607,7 +591,7 @@ baddbmm(beta=1, alpha=1, batch1, batch2) → Tensor¶ * * * ``` -baddbmm_(beta=1, alpha=1, batch1, batch2) → Tensor¶ +baddbmm_(beta=1, alpha=1, batch1, batch2) → Tensor ``` 就地版本的 [`baddbmm()`](#torch.Tensor.baddbmm "torch.Tensor.baddbmm") @@ -615,45 +599,25 @@ baddbmm_(beta=1, alpha=1, batch1, batch2) → Tensor¶ * * * ``` -bernoulli(*, generator=None) → Tensor¶ +bernoulli(*, generator=None) → Tensor ``` -返回结果张量,其中每个![](img/1a8008b0324a3d02d3103d9e62b33b0d.jpg)从![](img/d254f9481eaaf1650199b96c17e9b6b5.jpg)中独立采样。 `self`必须具有浮点`dtype`,结果将具有相同的`dtype`。 +返回结果张量,其中每个$result[i]$从$Bernoulli(self[i])$中独立采样。 `self`必须具有浮点`dtype`,结果将具有相同的`dtype`。 参见 [`torch.bernoulli()`](torch.html#torch.bernoulli "torch.bernoulli") * * * -``` -bernoulli_()¶ -``` - -* * * - ``` bernoulli_(p=0.5, *, generator=None) → Tensor ``` -用![](img/c9e211163142609f7991cd52490b5576.jpg)的独立样本填充`self`的每个位置。 `self`可以具有整数`dtype`。 - -* * * - -``` -bernoulli_(p_tensor, *, generator=None) → Tensor -``` - -`p_tensor`应该是一个张量,其中包含用于绘制二进制随机数的概率。 - -`self`张量的![](img/55a50814a1cfd1ab95d71ca3a7f311fb.jpg)元素将设置为从![](img/acccaf959a60719439f86fd943c2d27c.jpg)采样的值。 - -`self`可以具有整数`dtype`,但是`p_tensor`必须具有浮点`dtype`。 - -另请参见 [`bernoulli()`](#torch.Tensor.bernoulli "torch.Tensor.bernoulli") 和 [`torch.bernoulli()`](torch.html#torch.bernoulli "torch.bernoulli") +用$Bernoulli(p)$的独立样本填充`self`的每个位置。 `self`可以具有整数`dtype`。 * * * ``` -bfloat16() → Tensor¶ +bfloat16() → Tensor ``` `self.bfloat16()`等效于`self.to(torch.bfloat16)`。 参见 [`to()`](#torch.Tensor.to "torch.Tensor.to") 。 @@ -661,7 +625,7 @@ bfloat16() → Tensor¶ * * * ``` -bincount(weights=None, minlength=0) → Tensor¶ +bincount(weights=None, minlength=0) → Tensor ``` 参见 [`torch.bincount()`](torch.html#torch.bincount "torch.bincount") @@ -669,7 +633,7 @@ bincount(weights=None, minlength=0) → Tensor¶ * * * ``` -bitwise_not() → Tensor¶ +bitwise_not() → Tensor ``` 参见 [`torch.bitwise_not()`](torch.html#torch.bitwise_not "torch.bitwise_not") @@ -677,7 +641,7 @@ bitwise_not() → Tensor¶ * * * ``` -bitwise_not_() → Tensor¶ +bitwise_not_() → Tensor ``` 就地版本的 [`bitwise_not()`](#torch.Tensor.bitwise_not "torch.Tensor.bitwise_not") @@ -685,7 +649,7 @@ bitwise_not_() → Tensor¶ * * * ``` -bitwise_xor() → Tensor¶ +bitwise_xor() → Tensor ``` 参见 [`torch.bitwise_xor()`](torch.html#torch.bitwise_xor "torch.bitwise_xor") @@ -693,7 +657,7 @@ bitwise_xor() → Tensor¶ * * * ``` -bitwise_xor_() → Tensor¶ +bitwise_xor_() → Tensor ``` 就地版本的 [`bitwise_xor()`](#torch.Tensor.bitwise_xor "torch.Tensor.bitwise_xor") @@ -701,7 +665,7 @@ bitwise_xor_() → Tensor¶ * * * ``` -bmm(batch2) → Tensor¶ +bmm(batch2) → Tensor ``` 参见 [`torch.bmm()`](torch.html#torch.bmm "torch.bmm") @@ -709,7 +673,7 @@ bmm(batch2) → Tensor¶ * * * ``` -bool() → Tensor¶ +bool() → Tensor ``` `self.bool()`等效于`self.to(torch.bool)`。 参见 [`to()`](#torch.Tensor.to "torch.Tensor.to") 。 @@ -717,7 +681,7 @@ bool() → Tensor¶ * * * ``` -byte() → Tensor¶ +byte() → Tensor ``` `self.byte()`等效于`self.to(torch.uint8)`。 参见 [`to()`](#torch.Tensor.to "torch.Tensor.to") 。 @@ -725,17 +689,17 @@ byte() → Tensor¶ * * * ``` -cauchy_(median=0, sigma=1, *, generator=None) → Tensor¶ +cauchy_(median=0, sigma=1, *, generator=None) → Tensor ``` 用从柯西分布中得出的数字填充张量: -![](img/db253bf7891c8bf9a19a6f5280d7ac4c.jpg) +$$f(x)=\frac {1}{\pi}\frac {\sigma}{(x-median)^2+\sigma^2}$$ * * * ``` -ceil() → Tensor¶ +ceil() → Tensor ``` 参见 [`torch.ceil()`](torch.html#torch.ceil "torch.ceil") @@ -743,7 +707,7 @@ ceil() → Tensor¶ * * * ``` -ceil_() → Tensor¶ +ceil_() → Tensor ``` 就地版本的 [`ceil()`](#torch.Tensor.ceil "torch.Tensor.ceil") @@ -751,7 +715,7 @@ ceil_() → Tensor¶ * * * ``` -char() → Tensor¶ +char() → Tensor ``` `self.char()`等效于`self.to(torch.int8)`。 参见 [`to()`](#torch.Tensor.to "torch.Tensor.to") 。 @@ -759,7 +723,7 @@ char() → Tensor¶ * * * ``` -cholesky(upper=False) → Tensor¶ +cholesky(upper=False) → Tensor ``` 参见 [`torch.cholesky()`](torch.html#torch.cholesky "torch.cholesky") @@ -767,7 +731,7 @@ cholesky(upper=False) → Tensor¶ * * * ``` -cholesky_inverse(upper=False) → Tensor¶ +cholesky_inverse(upper=False) → Tensor ``` 参见 [`torch.cholesky_inverse()`](torch.html#torch.cholesky_inverse "torch.cholesky_inverse") @@ -775,7 +739,7 @@ cholesky_inverse(upper=False) → Tensor¶ * * * ``` -cholesky_solve(input2, upper=False) → Tensor¶ +cholesky_solve(input2, upper=False) → Tensor ``` 参见 [`torch.cholesky_solve()`](torch.html#torch.cholesky_solve "torch.cholesky_solve") @@ -783,7 +747,7 @@ cholesky_solve(input2, upper=False) → Tensor¶ * * * ``` -chunk(chunks, dim=0) → List of Tensors¶ +chunk(chunks, dim=0) → List of Tensors ``` 参见 [`torch.chunk()`](torch.html#torch.chunk "torch.chunk") @@ -791,7 +755,7 @@ chunk(chunks, dim=0) → List of Tensors¶ * * * ``` -clamp(min, max) → Tensor¶ +clamp(min, max) → Tensor ``` 参见 [`torch.clamp()`](torch.html#torch.clamp "torch.clamp") @@ -799,7 +763,7 @@ clamp(min, max) → Tensor¶ * * * ``` -clamp_(min, max) → Tensor¶ +clamp_(min, max) → Tensor ``` 就地版本的 [`clamp()`](#torch.Tensor.clamp "torch.Tensor.clamp") @@ -807,19 +771,19 @@ clamp_(min, max) → Tensor¶ * * * ``` -clone() → Tensor¶ +clone() → Tensor ``` 返回`self`张量的副本。 该副本的大小和数据类型与`self`相同。 -Note +注意 -与 <cite>copy_()</cite>不同,此功能记录在计算图中。 传播到克隆张量的渐变将传播到原始张量。 +与 _copy__()不同,此功能记录在计算图中。 传播到克隆张量的渐变将传播到原始张量。 * * * ``` -contiguous() → Tensor¶ +contiguous() → Tensor ``` 返回包含与`self`张量相同的数据的连续张量。 如果`self`张量是连续的,则此函数返回`self`张量。 @@ -827,14 +791,14 @@ contiguous() → Tensor¶ * * * ``` -copy_(src, non_blocking=False) → Tensor¶ +copy_(src, non_blocking=False) → Tensor ``` 将元素从`src`复制到`self`张量并返回`self`。 -`src`张量必须与`self`张量一起广播[。 它可以具有不同的数据类型,也可以位于不同的设备上。](notes/broadcasting.html#broadcasting-semantics) +`src`张量必须与`self`张量一起[广播](注意s/broadcasting.html#broadcasting-semantics)。 它可以具有不同的数据类型,也可以位于不同的设备上。 -Parameters +参数 * **src** ([_tensor_](#torch.Tensor "torch.Tensor"))–要从中复制的源张量 @@ -843,7 +807,7 @@ Parameters * * * ``` -conj() → Tensor¶ +conj() → Tensor ``` 参见 [`torch.conj()`](torch.html#torch.conj "torch.conj") @@ -851,7 +815,7 @@ conj() → Tensor¶ * * * ``` -cos() → Tensor¶ +cos() → Tensor ``` 参见 [`torch.cos()`](torch.html#torch.cos "torch.cos") @@ -859,7 +823,7 @@ cos() → Tensor¶ * * * ``` -cos_() → Tensor¶ +cos_() → Tensor ``` 就地版本的 [`cos()`](#torch.Tensor.cos "torch.Tensor.cos") @@ -867,7 +831,7 @@ cos_() → Tensor¶ * * * ``` -cosh() → Tensor¶ +cosh() → Tensor ``` 参见 [`torch.cosh()`](torch.html#torch.cosh "torch.cosh") @@ -875,7 +839,7 @@ cosh() → Tensor¶ * * * ``` -cosh_() → Tensor¶ +cosh_() → Tensor ``` 就地版本的 [`cosh()`](#torch.Tensor.cosh "torch.Tensor.cosh") @@ -883,7 +847,7 @@ cosh_() → Tensor¶ * * * ``` -cpu() → Tensor¶ +cpu() → Tensor ``` 返回此对象在 CPU 内存中的副本。 @@ -893,7 +857,7 @@ cpu() → Tensor¶ * * * ``` -cross(other, dim=-1) → Tensor¶ +cross(other, dim=-1) → Tensor ``` 参见 [`torch.cross()`](torch.html#torch.cross "torch.cross") @@ -901,23 +865,23 @@ cross(other, dim=-1) → Tensor¶ * * * ``` -cuda(device=None, non_blocking=False) → Tensor¶ +cuda(device=None, non_blocking=False) → Tensor ``` 返回此对象在 CUDA 内存中的副本。 如果此对象已经在 CUDA 内存中并且在正确的设备上,则不执行任何复制,并返回原始对象。 -Parameters +参数 -* **设备** ([`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device"))–目标 GPU 设备。 默认为当前 CUDA 设备。 +* **device** ([`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device")) – 目标 GPU 设备。 默认为当前 CUDA 设备。 -* **non_blocking** (_bool_ )–如果`True`并且源位于固定内存中,则副本将相对于主机是异步的。 否则,该参数无效。 默认值:`False`。 +* **non_blocking** (_bool_ ) – 如果`True`并且源位于固定内存中,则副本将相对于主机是异步的。 否则,该参数无效。 默认值:`False`。 * * * ``` -cumprod(dim, dtype=None) → Tensor¶ +cumprod(dim, dtype=None) → Tensor ``` 参见 [`torch.cumprod()`](torch.html#torch.cumprod "torch.cumprod") @@ -925,7 +889,7 @@ cumprod(dim, dtype=None) → Tensor¶ * * * ``` -cumsum(dim, dtype=None) → Tensor¶ +cumsum(dim, dtype=None) → Tensor ``` 参见 [`torch.cumsum()`](torch.html#torch.cumsum "torch.cumsum") @@ -933,7 +897,7 @@ cumsum(dim, dtype=None) → Tensor¶ * * * ``` -data_ptr() → int¶ +data_ptr() → int ``` 返回`self`张量的第一个元素的地址。 @@ -941,7 +905,7 @@ data_ptr() → int¶ * * * ``` -dequantize() → Tensor¶ +dequantize() → Tensor ``` 给定量化的张量,对其进行反量化,然后返回反量化后的浮点张量。 @@ -949,7 +913,7 @@ dequantize() → Tensor¶ * * * ``` -det() → Tensor¶ +det() → Tensor ``` 参见 [`torch.det()`](torch.html#torch.det "torch.det") @@ -957,7 +921,7 @@ det() → Tensor¶ * * * ``` -dense_dim() → int¶ +dense_dim() → int ``` 如果`self`是稀疏的 COO 张量(即`torch.sparse_coo`布局),则返回密集尺寸的数量。 否则,将引发错误。 @@ -972,11 +936,11 @@ detach() 返回与当前图形分离的新 Tensor。 -结果将永远不需要渐变。 +结果将永远不需要梯度。 -Note +注意 -返回的 Tensor 与原始 Tensor 共享相同的存储。 可以看到对它们中的任何一个的就地修改,并且可能触发正确性检查中的错误。 重要说明:以前,就地大小/步幅/存储更改(例如 <cite>resize_</cite> / <cite>resize_as_</cite> / <cite>set_</cite> / <cite>transpose_</cite> ) 返回的张量也会更新原始张量。 现在,这些就地更改将不再更新原始张量,而将触发错误。 对于稀疏张量:原位索引/值更改(例如 <cite>zero_</cite> / <cite>copy_</cite> / <cite>add_</cite> )将不会再更新原始张量, 而是触发错误。 +返回的 Tensor 与原始 Tensor 共享相同的存储。 可以看到对它们中的任何一个的就地修改,并且可能触发正确性检查中的错误。 重要说明:以前,就地大小/步幅/存储更改(例如 _resize__/_resize_as__/_set__/_transpose__) 返回的张量也会更新原始张量。 现在,这些就地更改将不再更新原始张量,而将触发错误。 对于稀疏张量:原位索引 / 值更改(例如 _zero__/_copy__/_add__)将不会再更新原始张量, 而是触发错误。 * * * @@ -989,7 +953,7 @@ detach_() * * * ``` -diag(diagonal=0) → Tensor¶ +diag(diagonal=0) → Tensor ``` 参见 [`torch.diag()`](torch.html#torch.diag "torch.diag") @@ -997,7 +961,7 @@ diag(diagonal=0) → Tensor¶ * * * ``` -diag_embed(offset=0, dim1=-2, dim2=-1) → Tensor¶ +diag_embed(offset=0, dim1=-2, dim2=-1) → Tensor ``` 参见 [`torch.diag_embed()`](torch.html#torch.diag_embed "torch.diag_embed") @@ -1005,7 +969,7 @@ diag_embed(offset=0, dim1=-2, dim2=-1) → Tensor¶ * * * ``` -diagflat(offset=0) → Tensor¶ +diagflat(offset=0) → Tensor ``` 参见 [`torch.diagflat()`](torch.html#torch.diagflat "torch.diagflat") @@ -1013,7 +977,7 @@ diagflat(offset=0) → Tensor¶ * * * ``` -diagonal(offset=0, dim1=0, dim2=1) → Tensor¶ +diagonal(offset=0, dim1=0, dim2=1) → Tensor ``` 参见 [`torch.diagonal()`](torch.html#torch.diagonal "torch.diagonal") @@ -1021,18 +985,18 @@ diagonal(offset=0, dim1=0, dim2=1) → Tensor¶ * * * ``` -fill_diagonal_(fill_value, wrap=False) → Tensor¶ +fill_diagonal_(fill_value, wrap=False) → Tensor ``` 填充具有至少 2 维的张量的主对角线。 当> 2 变暗时,所有输入尺寸必须相等。 此函数就地修改输入张量,并返回输入张量。 -Parameters +参数 -* **fill_value** (_标量_)–填充值 +* **fill_value** (_标量_)– 填充值 -* **包装** (_bool_ )–对角线“包裹”在高列的 N 列之后。 +* **wrap** (_bool_ ) – 对角线“包裹”在高列的 N 列之后。 -Example: +例: ``` >>> a = torch.zeros(3, 3) @@ -1064,7 +1028,7 @@ tensor([[5., 0., 0.], * * * ``` -digamma() → Tensor¶ +digamma() → Tensor ``` 参见 [`torch.digamma()`](torch.html#torch.digamma "torch.digamma") @@ -1072,7 +1036,7 @@ digamma() → Tensor¶ * * * ``` -digamma_() → Tensor¶ +digamma_() → Tensor ``` 就地版本的 [`digamma()`](#torch.Tensor.digamma "torch.Tensor.digamma") @@ -1080,7 +1044,7 @@ digamma_() → Tensor¶ * * * ``` -dim() → int¶ +dim() → int ``` 返回`self`张量的维数。 @@ -1088,7 +1052,7 @@ dim() → int¶ * * * ``` -dist(other, p=2) → Tensor¶ +dist(other, p=2) → Tensor ``` 参见 [`torch.dist()`](torch.html#torch.dist "torch.dist") @@ -1096,7 +1060,7 @@ dist(other, p=2) → Tensor¶ * * * ``` -div(value) → Tensor¶ +div(value) → Tensor ``` 参见 [`torch.div()`](torch.html#torch.div "torch.div") @@ -1104,7 +1068,7 @@ div(value) → Tensor¶ * * * ``` -div_(value) → Tensor¶ +div_(value) → Tensor ``` 就地版本的 [`div()`](#torch.Tensor.div "torch.Tensor.div") @@ -1112,7 +1076,7 @@ div_(value) → Tensor¶ * * * ``` -dot(tensor2) → Tensor¶ +dot(tensor2) → Tensor ``` 参见 [`torch.dot()`](torch.html#torch.dot "torch.dot") @@ -1120,7 +1084,7 @@ dot(tensor2) → Tensor¶ * * * ``` -double() → Tensor¶ +double() → Tensor ``` `self.double()`等效于`self.to(torch.float64)`。 参见 [`to()`](#torch.Tensor.to "torch.Tensor.to") 。 @@ -1128,7 +1092,7 @@ double() → Tensor¶ * * * ``` -eig(eigenvectors=False) -> (Tensor, Tensor)¶ +eig(eigenvectors=False) -> (Tensor, Tensor) ``` 参见 [`torch.eig()`](torch.html#torch.eig "torch.eig") @@ -1136,12 +1100,12 @@ eig(eigenvectors=False) -> (Tensor, Tensor)¶ * * * ``` -element_size() → int¶ +element_size() → int ``` 返回单个元素的大小(以字节为单位)。 -Example: +例: ``` >>> torch.tensor([]).element_size() @@ -1154,7 +1118,7 @@ Example: * * * ``` -eq(other) → Tensor¶ +eq(other) → Tensor ``` 参见 [`torch.eq()`](torch.html#torch.eq "torch.eq") @@ -1162,7 +1126,7 @@ eq(other) → Tensor¶ * * * ``` -eq_(other) → Tensor¶ +eq_(other) → Tensor ``` 就地版本的 [`eq()`](#torch.Tensor.eq "torch.Tensor.eq") @@ -1170,7 +1134,7 @@ eq_(other) → Tensor¶ * * * ``` -equal(other) → bool¶ +equal(other) → bool ``` 参见 [`torch.equal()`](torch.html#torch.equal "torch.equal") @@ -1178,7 +1142,7 @@ equal(other) → bool¶ * * * ``` -erf() → Tensor¶ +erf() → Tensor ``` 参见 [`torch.erf()`](torch.html#torch.erf "torch.erf") @@ -1186,7 +1150,7 @@ erf() → Tensor¶ * * * ``` -erf_() → Tensor¶ +erf_() → Tensor ``` 就地版本的 [`erf()`](#torch.Tensor.erf "torch.Tensor.erf") @@ -1194,7 +1158,7 @@ erf_() → Tensor¶ * * * ``` -erfc() → Tensor¶ +erfc() → Tensor ``` 参见 [`torch.erfc()`](torch.html#torch.erfc "torch.erfc") @@ -1202,7 +1166,7 @@ erfc() → Tensor¶ * * * ``` -erfc_() → Tensor¶ +erfc_() → Tensor ``` 就地版本的 [`erfc()`](#torch.Tensor.erfc "torch.Tensor.erfc") @@ -1210,7 +1174,7 @@ erfc_() → Tensor¶ * * * ``` -erfinv() → Tensor¶ +erfinv() → Tensor ``` 参见 [`torch.erfinv()`](torch.html#torch.erfinv "torch.erfinv") @@ -1218,7 +1182,7 @@ erfinv() → Tensor¶ * * * ``` -erfinv_() → Tensor¶ +erfinv_() → Tensor ``` 就地版本的 [`erfinv()`](#torch.Tensor.erfinv "torch.Tensor.erfinv") @@ -1226,7 +1190,7 @@ erfinv_() → Tensor¶ * * * ``` -exp() → Tensor¶ +exp() → Tensor ``` 参见 [`torch.exp()`](torch.html#torch.exp "torch.exp") @@ -1234,7 +1198,7 @@ exp() → Tensor¶ * * * ``` -exp_() → Tensor¶ +exp_() → Tensor ``` 就地版本的 [`exp()`](#torch.Tensor.exp "torch.Tensor.exp") @@ -1242,7 +1206,7 @@ exp_() → Tensor¶ * * * ``` -expm1() → Tensor¶ +expm1() → Tensor ``` 参见 [`torch.expm1()`](torch.html#torch.expm1 "torch.expm1") @@ -1250,7 +1214,7 @@ expm1() → Tensor¶ * * * ``` -expm1_() → Tensor¶ +expm1_() → Tensor ``` 就地版本的 [`expm1()`](#torch.Tensor.expm1 "torch.Tensor.expm1") @@ -1258,7 +1222,7 @@ expm1_() → Tensor¶ * * * ``` -expand(*sizes) → Tensor¶ +expand(*sizes) → Tensor ``` 返回`self`张量的新视图,其中单例尺寸扩展为更大的尺寸。 @@ -1269,15 +1233,15 @@ Tensor 也可以扩展到更大的尺寸,并且新尺寸将附加在前面。 扩展张量不会分配新的内存,而只会在现有张量上创建一个新视图,其中通过将`stride`设置为 0,将尺寸为 1 的维扩展为更大的尺寸。尺寸为 1 的任何维都可以扩展为 不分配新内存的任意值。 -Parameters +参数 ***大小**(_torch大小_ _或_ _python:int ..._ )–所需的扩展大小 -Warning +警告 扩展张量的一个以上元素可以引用单个存储位置。 结果,就地操作(尤其是矢量化的操作)可能会导致错误的行为。 如果需要写张量,请先克隆它们。 -Example: +例: ``` >>> x = torch.tensor([[1], [2], [3]]) @@ -1297,31 +1261,31 @@ tensor([[ 1, 1, 1, 1], * * * ``` -expand_as(other) → Tensor¶ +expand_as(other) → Tensor ``` 将该张量扩展为与`other`相同的大小。 `self.expand_as(other)`等效于`self.expand(other.size())`。 有关`expand`的更多信息,请参见 [`expand()`](#torch.Tensor.expand "torch.Tensor.expand") 。 -Parameters +参数 **其他** ([`torch.Tensor`](#torch.Tensor "torch.Tensor"))–结果张量的大小与`other`相同。 * * * ``` -exponential_(lambd=1, *, generator=None) → Tensor¶ +exponential_(lambd=1, *, generator=None) → Tensor ``` 用从指数分布中绘制的元素填充`self`张量: -![](img/c2fc559096933893bcb6078fee146c8c.jpg) +$$f(x)=\lambda e^{-\lambda x}$$ * * * ``` -fft(signal_ndim, normalized=False) → Tensor¶ +fft(signal_ndim, normalized=False) → Tensor ``` 参见 [`torch.fft()`](torch.html#torch.fft "torch.fft") @@ -1329,7 +1293,7 @@ fft(signal_ndim, normalized=False) → Tensor¶ * * * ``` -fill_(value) → Tensor¶ +fill_(value) → Tensor ``` 用指定值填充`self`张量。 @@ -1337,7 +1301,7 @@ fill_(value) → Tensor¶ * * * ``` -flatten(input, start_dim=0, end_dim=-1) → Tensor¶ +flatten(input, start_dim=0, end_dim=-1) → Tensor ``` 参见 [`torch.flatten()`](torch.html#torch.flatten "torch.flatten") @@ -1345,7 +1309,7 @@ flatten(input, start_dim=0, end_dim=-1) → Tensor¶ * * * ``` -flip(dims) → Tensor¶ +flip(dims) → Tensor ``` 参见 [`torch.flip()`](torch.html#torch.flip "torch.flip") @@ -1353,7 +1317,7 @@ flip(dims) → Tensor¶ * * * ``` -float() → Tensor¶ +float() → Tensor ``` `self.float()`等效于`self.to(torch.float32)`。 参见 [`to()`](#torch.Tensor.to "torch.Tensor.to") 。 @@ -1361,7 +1325,7 @@ float() → Tensor¶ * * * ``` -floor() → Tensor¶ +floor() → Tensor ``` 参见 [`torch.floor()`](torch.html#torch.floor "torch.floor") @@ -1369,7 +1333,7 @@ floor() → Tensor¶ * * * ``` -floor_() → Tensor¶ +floor_() → Tensor ``` 就地版本的 [`floor()`](#torch.Tensor.floor "torch.Tensor.floor") @@ -1377,7 +1341,7 @@ floor_() → Tensor¶ * * * ``` -fmod(divisor) → Tensor¶ +fmod(divisor) → Tensor ``` 参见 [`torch.fmod()`](torch.html#torch.fmod "torch.fmod") @@ -1385,7 +1349,7 @@ fmod(divisor) → Tensor¶ * * * ``` -fmod_(divisor) → Tensor¶ +fmod_(divisor) → Tensor ``` 就地版本的 [`fmod()`](#torch.Tensor.fmod "torch.Tensor.fmod") @@ -1393,7 +1357,7 @@ fmod_(divisor) → Tensor¶ * * * ``` -frac() → Tensor¶ +frac() → Tensor ``` 参见 [`torch.frac()`](torch.html#torch.frac "torch.frac") @@ -1401,7 +1365,7 @@ frac() → Tensor¶ * * * ``` -frac_() → Tensor¶ +frac_() → Tensor ``` 就地版本的 [`frac()`](#torch.Tensor.frac "torch.Tensor.frac") @@ -1409,7 +1373,7 @@ frac_() → Tensor¶ * * * ``` -gather(dim, index) → Tensor¶ +gather(dim, index) → Tensor ``` 参见 [`torch.gather()`](torch.html#torch.gather "torch.gather") @@ -1417,7 +1381,7 @@ gather(dim, index) → Tensor¶ * * * ``` -ge(other) → Tensor¶ +ge(other) → Tensor ``` 参见 [`torch.ge()`](torch.html#torch.ge "torch.ge") @@ -1425,7 +1389,7 @@ ge(other) → Tensor¶ * * * ``` -ge_(other) → Tensor¶ +ge_(other) → Tensor ``` 就地版本的 [`ge()`](#torch.Tensor.ge "torch.Tensor.ge") @@ -1433,17 +1397,17 @@ ge_(other) → Tensor¶ * * * ``` -geometric_(p, *, generator=None) → Tensor¶ +geometric_(p, *, generator=None) → Tensor ``` 用从几何分布中绘制的元素填充`self`张量: -![](img/6654ffe5db290d48a20697d02e41bda4.jpg) +$$f(X=k)=p^{k-1}(1-p)$$ * * * ``` -geqrf() -> (Tensor, Tensor)¶ +geqrf() -> (Tensor, Tensor) ``` 参见 [`torch.geqrf()`](torch.html#torch.geqrf "torch.geqrf") @@ -1451,7 +1415,7 @@ geqrf() -> (Tensor, Tensor)¶ * * * ``` -ger(vec2) → Tensor¶ +ger(vec2) → Tensor ``` 参见 [`torch.ger()`](torch.html#torch.ger "torch.ger") @@ -1459,12 +1423,12 @@ ger(vec2) → Tensor¶ * * * ``` -get_device() -> Device ordinal (Integer)¶ +get_device() -> Device ordinal (Integer) ``` 对于 CUDA 张量,此函数返回张量所在的 GPU 的设备序号。 对于 CPU 张量,将引发错误。 -Example: +例: ``` >>> x = torch.randn(3, 4, 5, device='cuda:0') @@ -1477,7 +1441,7 @@ Example: * * * ``` -gt(other) → Tensor¶ +gt(other) → Tensor ``` 参见 [`torch.gt()`](torch.html#torch.gt "torch.gt") @@ -1485,7 +1449,7 @@ gt(other) → Tensor¶ * * * ``` -gt_(other) → Tensor¶ +gt_(other) → Tensor ``` 就地版本的 [`gt()`](#torch.Tensor.gt "torch.Tensor.gt") @@ -1493,7 +1457,7 @@ gt_(other) → Tensor¶ * * * ``` -half() → Tensor¶ +half() → Tensor ``` `self.half()`等效于`self.to(torch.float16)`。 参见 [`to()`](#torch.Tensor.to "torch.Tensor.to") 。 @@ -1501,7 +1465,7 @@ half() → Tensor¶ * * * ``` -hardshrink(lambd=0.5) → Tensor¶ +hardshrink(lambd=0.5) → Tensor ``` 参见 [`torch.nn.functional.hardshrink()`](nn.functional.html#torch.nn.functional.hardshrink "torch.nn.functional.hardshrink") @@ -1509,7 +1473,7 @@ hardshrink(lambd=0.5) → Tensor¶ * * * ``` -histc(bins=100, min=0, max=0) → Tensor¶ +histc(bins=100, min=0, max=0) → Tensor ``` 参见 [`torch.histc()`](torch.html#torch.histc "torch.histc") @@ -1517,7 +1481,7 @@ histc(bins=100, min=0, max=0) → Tensor¶ * * * ``` -ifft(signal_ndim, normalized=False) → Tensor¶ +ifft(signal_ndim, normalized=False) → Tensor ``` 参见 [`torch.ifft()`](torch.html#torch.ifft "torch.ifft") @@ -1525,7 +1489,7 @@ ifft(signal_ndim, normalized=False) → Tensor¶ * * * ``` -imag() → Tensor¶ +imag() → Tensor ``` 参见 [`torch.imag()`](torch.html#torch.imag "torch.imag") @@ -1533,26 +1497,26 @@ imag() → Tensor¶ * * * ``` -index_add_(dim, index, tensor) → Tensor¶ +index_add_(dim, index, tensor) → Tensor ``` 通过按`index`中给定的顺序添加索引,将 [`tensor`](torch.html#torch.tensor "torch.tensor") 的元素累积到`self`张量中。 例如,如果`dim == 0`和`index[i] == j`,则将[的第`i`行`tensor`](torch.html#torch.tensor "torch.tensor") 添加到`self`的第`j`行。 [`tensor`](torch.html#torch.tensor "torch.tensor") 的 [`dim`](#torch.Tensor.dim "torch.Tensor.dim") 尺寸必须与`index`的长度(必须为矢量)的尺寸相同,并且所有其他尺寸必须与`self` ],否则将引发错误。 -Note +注意 -使用 CUDA 后端时,此操作可能会导致不确定的行为,不容易关闭。 有关背景,请参见[重现性](notes/randomness.html)的注释。 +使用 CUDA 后端时,此操作可能会导致不确定的行为,不容易关闭。 有关背景,请参见[重现性](注意s/randomness.html)的注释。 -Parameters +参数 -* **暗淡的** (_python:int_ )–索引所沿的维度 +* **dim** (_python:int_ )–索引所沿的维度 * **索引** (_LongTensor_ )– [`tensor`](torch.html#torch.tensor "torch.tensor") 的索引 * **张量** ([_tensor_](#torch.Tensor "torch.Tensor"))–张量包含要添加的值 -Example: +例: ``` >>> x = torch.ones(5, 3) @@ -1570,7 +1534,7 @@ tensor([[ 2., 3., 4.], * * * ``` -index_add(dim, index, tensor) → Tensor¶ +index_add(dim, index, tensor) → Tensor ``` [`torch.Tensor.index_add_()`](#torch.Tensor.index_add_ "torch.Tensor.index_add_") 的替代版本 @@ -1578,14 +1542,14 @@ index_add(dim, index, tensor) → Tensor¶ * * * ``` -index_copy_(dim, index, tensor) → Tensor¶ +index_copy_(dim, index, tensor) → Tensor ``` 通过按`index`中给定的顺序选择索引,将 [`tensor`](torch.html#torch.tensor "torch.tensor") 的元素复制到`self`张量中。 例如,如果`dim == 0`和`index[i] == j`,则将 [`tensor`](torch.html#torch.tensor "torch.tensor") 的第`i`行复制到`self`的第`j`行。 The [`dim`](#torch.Tensor.dim "torch.Tensor.dim")th dimension of [`tensor`](torch.html#torch.tensor "torch.tensor") must have the same size as the length of `index` (which must be a vector), and all other dimensions must match `self`, or an error will be raised. -Parameters +参数 * **dim** (_python:int_) – dimension along which to index @@ -1593,7 +1557,7 @@ Parameters * **张量** ([_tensor_](#torch.Tensor "torch.Tensor"))–张量包含要复制的值 -Example: +例: ``` >>> x = torch.zeros(5, 3) @@ -1611,7 +1575,7 @@ tensor([[ 1., 2., 3.], * * * ``` -index_copy(dim, index, tensor) → Tensor¶ +index_copy(dim, index, tensor) → Tensor ``` [`torch.Tensor.index_copy_()`](#torch.Tensor.index_copy_ "torch.Tensor.index_copy_") 的替代版本 @@ -1619,12 +1583,12 @@ index_copy(dim, index, tensor) → Tensor¶ * * * ``` -index_fill_(dim, index, val) → Tensor¶ +index_fill_(dim, index, val) → Tensor ``` 通过按`index`中给定的顺序选择索引,用值`val`填充`self`张量的元素。 -Parameters +参数 * **dim** (_python:int_) – dimension along which to index @@ -1633,7 +1597,7 @@ Parameters * **val** (_python:float_ )–要填充的值 ``` -Example:: +例:: ``` ``` @@ -1649,7 +1613,7 @@ tensor([[-1., 2., -1.], * * * ``` -index_fill(dim, index, value) → Tensor¶ +index_fill(dim, index, value) → Tensor ``` [`torch.Tensor.index_fill_()`](#torch.Tensor.index_fill_ "torch.Tensor.index_fill_") 的替代版本 @@ -1657,14 +1621,14 @@ index_fill(dim, index, value) → Tensor¶ * * * ``` -index_put_(indices, value, accumulate=False) → Tensor¶ +index_put_(indices, value, accumulate=False) → Tensor ``` 使用在 [`indices`](#torch.Tensor.indices "torch.Tensor.indices") 中指定的索引(张量的元组)将张量`value`的值放入张量`self`。 表达式`tensor.index_put_(indices, value)`等效于`tensor[indices] = value`。 返回`self`。 如果`accumulate`为`True`,则将 [`tensor`](torch.html#torch.tensor "torch.tensor") 中的元素添加到`self`中。 如果 accumulate 为`False`,则在索引包含重复元素的情况下行为未定义。 -Parameters +参数 * **索引**(LongTensor 的_元组)–用于索引<cite>自身</cite>的张量。_ @@ -1675,7 +1639,7 @@ Parameters * * * ``` -index_put(indices, value, accumulate=False) → Tensor¶ +index_put(indices, value, accumulate=False) → Tensor ``` [`index_put_()`](#torch.Tensor.index_put_ "torch.Tensor.index_put_") 的替代版本 @@ -1683,7 +1647,7 @@ index_put(indices, value, accumulate=False) → Tensor¶ * * * ``` -index_select(dim, index) → Tensor¶ +index_select(dim, index) → Tensor ``` 参见 [`torch.index_select()`](torch.html#torch.index_select "torch.index_select") @@ -1691,21 +1655,21 @@ index_select(dim, index) → Tensor¶ * * * ``` -indices() → Tensor¶ +indices() → Tensor ``` 如果`self`是稀疏的 COO 张量(即`torch.sparse_coo`布局),则返回包含的索引张量的视图。 否则,将引发错误。 另请参见 [`Tensor.values()`](#torch.Tensor.values "torch.Tensor.values") 。 -Note +注意 只能在合并的稀疏张量上调用此方法。 有关详细信息,请参见`Tensor.coalesce()`。 * * * ``` -int() → Tensor¶ +int() → Tensor ``` `self.int()`等效于`self.to(torch.int32)`。 参见 [`to()`](#torch.Tensor.to "torch.Tensor.to") 。 @@ -1713,7 +1677,7 @@ int() → Tensor¶ * * * ``` -int_repr() → Tensor¶ +int_repr() → Tensor ``` 给定量化的 Tensor,`self.int_repr()`返回以 uint8_t 作为数据类型的 CPU Tensor,该数据类型存储给定 Tensor 的基础 uint8_t 值。 @@ -1721,7 +1685,7 @@ int_repr() → Tensor¶ * * * ``` -inverse() → Tensor¶ +inverse() → Tensor ``` 参见 [`torch.inverse()`](torch.html#torch.inverse "torch.inverse") @@ -1729,7 +1693,7 @@ inverse() → Tensor¶ * * * ``` -irfft(signal_ndim, normalized=False, onesided=True, signal_sizes=None) → Tensor¶ +irfft(signal_ndim, normalized=False, onesided=True, signal_sizes=None) → Tensor ``` 参见 [`torch.irfft()`](torch.html#torch.irfft "torch.irfft") @@ -1737,7 +1701,7 @@ irfft(signal_ndim, normalized=False, onesided=True, signal_sizes=None) → Tenso * * * ``` -is_contiguous() → bool¶ +is_contiguous() → bool ``` 如果`self`张量在内存中以 C 顺序连续,则返回 True。 @@ -1745,7 +1709,7 @@ is_contiguous() → bool¶ * * * ``` -is_floating_point() → bool¶ +is_floating_point() → bool ``` 如果`self`的数据类型是浮点数据类型,则返回 True。 @@ -1760,7 +1724,7 @@ is_leaf 在调用 [`backward()`](autograd.html#torch.Tensor.backward "torch.Tensor.backward") 期间,仅叶子张量会填充其 [`grad`](autograd.html#torch.Tensor.grad "torch.Tensor.grad") 。 要为非叶张量填充 [`grad`](autograd.html#torch.Tensor.grad "torch.Tensor.grad") ,可以使用 [`retain_grad()`](autograd.html#torch.Tensor.retain_grad "torch.Tensor.retain_grad") 。 -Example: +例: ``` >>> a = torch.rand(10, requires_grad=True) @@ -1792,7 +1756,7 @@ True * * * ``` -is_pinned()¶ +is_pinned() ``` 如果该张量驻留在固定的内存中,则返回 true。 @@ -1800,7 +1764,7 @@ is_pinned()¶ * * * ``` -is_set_to(tensor) → bool¶ +is_set_to(tensor) → bool ``` 如果此对象引用与 Torch C API 中相同的`THTensor`对象作为给定张量,则返回 True。 @@ -1808,7 +1772,7 @@ is_set_to(tensor) → bool¶ * * * ``` -is_shared()¶ +is_shared() ``` 检查张量是否在共享内存中。 @@ -1818,26 +1782,26 @@ CUDA 张量始终为`True`。 * * * ``` -is_signed() → bool¶ +is_signed() → bool ``` 如果`self`的数据类型是带符号的数据类型,则返回 True。 ``` -is_sparse¶ +is_sparse ``` * * * ``` -item() → number¶ +item() → number ``` 返回此张量的值作为标准 Python 数。 这仅适用于具有一个元素的张量。 对于其他情况,请参见 [`tolist()`](#torch.Tensor.tolist "torch.Tensor.tolist") 。 此操作不可区分。 -Example: +例: ``` >>> x = torch.tensor([1.0]) @@ -1849,7 +1813,7 @@ Example: * * * ``` -kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)¶ +kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor) ``` 参见 [`torch.kthvalue()`](torch.html#torch.kthvalue "torch.kthvalue") @@ -1857,7 +1821,7 @@ kthvalue(k, dim=None, keepdim=False) -> (Tensor, LongTensor)¶ * * * ``` -le(other) → Tensor¶ +le(other) → Tensor ``` 参见 [`torch.le()`](torch.html#torch.le "torch.le") @@ -1865,7 +1829,7 @@ le(other) → Tensor¶ * * * ``` -le_(other) → Tensor¶ +le_(other) → Tensor ``` 就地版本的 [`le()`](#torch.Tensor.le "torch.Tensor.le") @@ -1873,7 +1837,7 @@ le_(other) → Tensor¶ * * * ``` -lerp(end, weight) → Tensor¶ +lerp(end, weight) → Tensor ``` 参见 [`torch.lerp()`](torch.html#torch.lerp "torch.lerp") @@ -1881,7 +1845,7 @@ lerp(end, weight) → Tensor¶ * * * ``` -lerp_(end, weight) → Tensor¶ +lerp_(end, weight) → Tensor ``` 就地版本的 [`lerp()`](#torch.Tensor.lerp "torch.Tensor.lerp") @@ -1889,7 +1853,7 @@ lerp_(end, weight) → Tensor¶ * * * ``` -lgamma() → Tensor¶ +lgamma() → Tensor ``` 参见 [`torch.lgamma()`](torch.html#torch.lgamma "torch.lgamma") @@ -1897,7 +1861,7 @@ lgamma() → Tensor¶ * * * ``` -lgamma_() → Tensor¶ +lgamma_() → Tensor ``` 就地版本的 [`lgamma()`](#torch.Tensor.lgamma "torch.Tensor.lgamma") @@ -1905,7 +1869,7 @@ lgamma_() → Tensor¶ * * * ``` -log() → Tensor¶ +log() → Tensor ``` 参见 [`torch.log()`](torch.html#torch.log "torch.log") @@ -1913,7 +1877,7 @@ log() → Tensor¶ * * * ``` -log_() → Tensor¶ +log_() → Tensor ``` 就地版本的 [`log()`](#torch.Tensor.log "torch.Tensor.log") @@ -1921,7 +1885,7 @@ log_() → Tensor¶ * * * ``` -logdet() → Tensor¶ +logdet() → Tensor ``` 参见 [`torch.logdet()`](torch.html#torch.logdet "torch.logdet") @@ -1929,7 +1893,7 @@ logdet() → Tensor¶ * * * ``` -log10() → Tensor¶ +log10() → Tensor ``` 参见 [`torch.log10()`](torch.html#torch.log10 "torch.log10") @@ -1937,7 +1901,7 @@ log10() → Tensor¶ * * * ``` -log10_() → Tensor¶ +log10_() → Tensor ``` 就地版本的 [`log10()`](#torch.Tensor.log10 "torch.Tensor.log10") @@ -1945,7 +1909,7 @@ log10_() → Tensor¶ * * * ``` -log1p() → Tensor¶ +log1p() → Tensor ``` 参见 [`torch.log1p()`](torch.html#torch.log1p "torch.log1p") @@ -1953,7 +1917,7 @@ log1p() → Tensor¶ * * * ``` -log1p_() → Tensor¶ +log1p_() → Tensor ``` 就地版本的 [`log1p()`](#torch.Tensor.log1p "torch.Tensor.log1p") @@ -1961,7 +1925,7 @@ log1p_() → Tensor¶ * * * ``` -log2() → Tensor¶ +log2() → Tensor ``` 参见 [`torch.log2()`](torch.html#torch.log2 "torch.log2") @@ -1969,7 +1933,7 @@ log2() → Tensor¶ * * * ``` -log2_() → Tensor¶ +log2_() → Tensor ``` 就地版本的 [`log2()`](#torch.Tensor.log2 "torch.Tensor.log2") @@ -1977,17 +1941,17 @@ log2_() → Tensor¶ * * * ``` -log_normal_(mean=1, std=2, *, generator=None)¶ +log_normal_(mean=1, std=2, *, generator=None) ``` 用对数正态分布中由给定平均值![](img/fba1f12214374ac856c1e4be142c9dff.jpg)和标准偏差![](img/cc84e998f72a1c5a0a5f736ba6a9ff34.jpg)参数化的数字样本填充`self`张量。 请注意, [`mean`](torch.html#torch.mean "torch.mean") 和 [`std`](torch.html#torch.std "torch.std") 是基础正态分布的均值和标准偏差,而不是返回的正态分布: -![](img/7e5d2e8735d5194d1ed5c42cfd875ebd.jpg) +$$f(x)=\frac {1}{x\sigma \sqrt {2\pi}}e^{-\frac {(lnx - \mu)^2}{2\sigma^2}}$$ * * * ``` -logsumexp(dim, keepdim=False) → Tensor¶ +logsumexp(dim, keepdim=False) → Tensor ``` 参见 [`torch.logsumexp()`](torch.html#torch.logsumexp "torch.logsumexp") @@ -1995,7 +1959,7 @@ logsumexp(dim, keepdim=False) → Tensor¶ * * * ``` -logical_not() → Tensor¶ +logical_not() → Tensor ``` 参见 [`torch.logical_not()`](torch.html#torch.logical_not "torch.logical_not") @@ -2003,7 +1967,7 @@ logical_not() → Tensor¶ * * * ``` -logical_not_() → Tensor¶ +logical_not_() → Tensor ``` 就地版本的 [`logical_not()`](#torch.Tensor.logical_not "torch.Tensor.logical_not") @@ -2011,7 +1975,7 @@ logical_not_() → Tensor¶ * * * ``` -logical_xor() → Tensor¶ +logical_xor() → Tensor ``` 参见 [`torch.logical_xor()`](torch.html#torch.logical_xor "torch.logical_xor") @@ -2019,7 +1983,7 @@ logical_xor() → Tensor¶ * * * ``` -logical_xor_() → Tensor¶ +logical_xor_() → Tensor ``` 就地版本的 [`logical_xor()`](#torch.Tensor.logical_xor "torch.Tensor.logical_xor") @@ -2027,7 +1991,7 @@ logical_xor_() → Tensor¶ * * * ``` -long() → Tensor¶ +long() → Tensor ``` `self.long()`等效于`self.to(torch.int64)`。 参见 [`to()`](#torch.Tensor.to "torch.Tensor.to") 。 @@ -2035,7 +1999,7 @@ long() → Tensor¶ * * * ``` -lstsq(A) -> (Tensor, Tensor)¶ +lstsq(A) -> (Tensor, Tensor) ``` 参见 [`torch.lstsq()`](torch.html#torch.lstsq "torch.lstsq") @@ -2043,7 +2007,7 @@ lstsq(A) -> (Tensor, Tensor)¶ * * * ``` -lt(other) → Tensor¶ +lt(other) → Tensor ``` 参见 [`torch.lt()`](torch.html#torch.lt "torch.lt") @@ -2051,7 +2015,7 @@ lt(other) → Tensor¶ * * * ``` -lt_(other) → Tensor¶ +lt_(other) → Tensor ``` 就地版本的 [`lt()`](#torch.Tensor.lt "torch.Tensor.lt") @@ -2059,7 +2023,7 @@ lt_(other) → Tensor¶ * * * ``` -lu(pivot=True, get_infos=False)¶ +lu(pivot=True, get_infos=False) ``` 参见 [`torch.lu()`](torch.html#torch.lu "torch.lu") @@ -2067,7 +2031,7 @@ lu(pivot=True, get_infos=False)¶ * * * ``` -lu_solve(LU_data, LU_pivots) → Tensor¶ +lu_solve(LU_data, LU_pivots) → Tensor ``` 参见 [`torch.lu_solve()`](torch.html#torch.lu_solve "torch.lu_solve") @@ -2075,10 +2039,10 @@ lu_solve(LU_data, LU_pivots) → Tensor¶ * * * ``` -map_(tensor, callable)¶ +map_(tensor, callable) ``` -对`self`张量中的每个元素和给定的 [`tensor`](torch.html#torch.tensor "torch.tensor") 应用`callable`,并将结果存储在`self`张量中。 `self`张量和给定的 [`tensor`](torch.html#torch.tensor "torch.tensor") 必须是[可广播的](notes/broadcasting.html#broadcasting-semantics)。 +对`self`张量中的每个元素和给定的 [`tensor`](torch.html#torch.tensor "torch.tensor") 应用`callable`,并将结果存储在`self`张量中。 `self`张量和给定的 [`tensor`](torch.html#torch.tensor "torch.tensor") 必须是[可广播的](注意s/broadcasting.html#broadcasting-semantics)。 `callable`应具有签名: @@ -2090,25 +2054,25 @@ def callable(a, b) -> number * * * ``` -masked_scatter_(mask, source)¶ +masked_scatter_(mask, source) ``` -在`mask`为 True 的位置将元素从`source`复制到`self`张量。 `mask`的形状必须是[可广播的](notes/broadcasting.html#broadcasting-semantics),并具有基础张量的形状。 `source`中的元素数量至少应与`mask`中的元素数量一样多。 +在`mask`为 True 的位置将元素从`source`复制到`self`张量。 `mask`的形状必须是[可广播的](注意s/broadcasting.html#broadcasting-semantics),并具有基础张量的形状。 `source`中的元素数量至少应与`mask`中的元素数量一样多。 -Parameters +参数 * **掩码** ([_BoolTensor_](#torch.BoolTensor "torch.BoolTensor"))–布尔掩码 * **源** ([_tensor_](#torch.Tensor "torch.Tensor"))–要从中复制的张量 -Note +注意 `mask`在`self`张量上运行,而不是在给定的`source`张量上运行。 * * * ``` -masked_scatter(mask, tensor) → Tensor¶ +masked_scatter(mask, tensor) → Tensor ``` [`torch.Tensor.masked_scatter_()`](#torch.Tensor.masked_scatter_ "torch.Tensor.masked_scatter_") 的替代版本 @@ -2116,12 +2080,12 @@ masked_scatter(mask, tensor) → Tensor¶ * * * ``` -masked_fill_(mask, value)¶ +masked_fill_(mask, value) ``` -用`value`填充`self`张量的元素,其中`mask`为 True。 `mask`的形状必须是[可广播的](notes/broadcasting.html#broadcasting-semantics),并具有基础张量的形状。 +用`value`填充`self`张量的元素,其中`mask`为 True。 `mask`的形状必须是[可广播的](注意s/broadcasting.html#broadcasting-semantics),并具有基础张量的形状。 -Parameters +参数 * **mask** ([_BoolTensor_](#torch.BoolTensor "torch.BoolTensor")) – the boolean mask @@ -2130,7 +2094,7 @@ Parameters * * * ``` -masked_fill(mask, value) → Tensor¶ +masked_fill(mask, value) → Tensor ``` [`torch.Tensor.masked_fill_()`](#torch.Tensor.masked_fill_ "torch.Tensor.masked_fill_") 的替代版本 @@ -2138,7 +2102,7 @@ masked_fill(mask, value) → Tensor¶ * * * ``` -masked_select(mask) → Tensor¶ +masked_select(mask) → Tensor ``` 参见 [`torch.masked_select()`](torch.html#torch.masked_select "torch.masked_select") @@ -2146,7 +2110,7 @@ masked_select(mask) → Tensor¶ * * * ``` -matmul(tensor2) → Tensor¶ +matmul(tensor2) → Tensor ``` 参见 [`torch.matmul()`](torch.html#torch.matmul "torch.matmul") @@ -2154,7 +2118,7 @@ matmul(tensor2) → Tensor¶ * * * ``` -matrix_power(n) → Tensor¶ +matrix_power(n) → Tensor ``` 参见 [`torch.matrix_power()`](torch.html#torch.matrix_power "torch.matrix_power") @@ -2162,7 +2126,7 @@ matrix_power(n) → Tensor¶ * * * ``` -max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)¶ +max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor) ``` 参见 [`torch.max()`](torch.html#torch.max "torch.max") @@ -2170,7 +2134,7 @@ max(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)¶ * * * ``` -mean(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)¶ +mean(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor) ``` 参见 [`torch.mean()`](torch.html#torch.mean "torch.mean") @@ -2178,7 +2142,7 @@ mean(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)¶ * * * ``` -median(dim=None, keepdim=False) -> (Tensor, LongTensor)¶ +median(dim=None, keepdim=False) -> (Tensor, LongTensor) ``` 参见 [`torch.median()`](torch.html#torch.median "torch.median") @@ -2186,7 +2150,7 @@ median(dim=None, keepdim=False) -> (Tensor, LongTensor)¶ * * * ``` -min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)¶ +min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor) ``` 参见 [`torch.min()`](torch.html#torch.min "torch.min") @@ -2194,7 +2158,7 @@ min(dim=None, keepdim=False) -> Tensor or (Tensor, Tensor)¶ * * * ``` -mm(mat2) → Tensor¶ +mm(mat2) → Tensor ``` 参见 [`torch.mm()`](torch.html#torch.mm "torch.mm") @@ -2202,7 +2166,7 @@ mm(mat2) → Tensor¶ * * * ``` -mode(dim=None, keepdim=False) -> (Tensor, LongTensor)¶ +mode(dim=None, keepdim=False) -> (Tensor, LongTensor) ``` 参见 [`torch.mode()`](torch.html#torch.mode "torch.mode") @@ -2210,7 +2174,7 @@ mode(dim=None, keepdim=False) -> (Tensor, LongTensor)¶ * * * ``` -mul(value) → Tensor¶ +mul(value) → Tensor ``` 参见 [`torch.mul()`](torch.html#torch.mul "torch.mul") @@ -2218,7 +2182,7 @@ mul(value) → Tensor¶ * * * ``` -mul_(value)¶ +mul_(value) ``` 就地版本的 [`mul()`](#torch.Tensor.mul "torch.Tensor.mul") @@ -2226,7 +2190,7 @@ mul_(value)¶ * * * ``` -multinomial(num_samples, replacement=False, *, generator=None) → Tensor¶ +multinomial(num_samples, replacement=False, *, generator=None) → Tensor ``` 参见 [`torch.multinomial()`](torch.html#torch.multinomial "torch.multinomial") @@ -2234,7 +2198,7 @@ multinomial(num_samples, replacement=False, *, generator=None) → Tensor¶ * * * ``` -mv(vec) → Tensor¶ +mv(vec) → Tensor ``` 参见 [`torch.mv()`](torch.html#torch.mv "torch.mv") @@ -2242,7 +2206,7 @@ mv(vec) → Tensor¶ * * * ``` -mvlgamma(p) → Tensor¶ +mvlgamma(p) → Tensor ``` 参见 [`torch.mvlgamma()`](torch.html#torch.mvlgamma "torch.mvlgamma") @@ -2250,7 +2214,7 @@ mvlgamma(p) → Tensor¶ * * * ``` -mvlgamma_(p) → Tensor¶ +mvlgamma_(p) → Tensor ``` 就地版本的 [`mvlgamma()`](#torch.Tensor.mvlgamma "torch.Tensor.mvlgamma") @@ -2258,12 +2222,12 @@ mvlgamma_(p) → Tensor¶ * * * ``` -narrow(dimension, start, length) → Tensor¶ +narrow(dimension, start, length) → Tensor ``` 参见 [`torch.narrow()`](torch.html#torch.narrow "torch.narrow") -Example: +例: ``` >>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) @@ -2280,7 +2244,7 @@ tensor([[ 2, 3], * * * ``` -narrow_copy(dimension, start, length) → Tensor¶ +narrow_copy(dimension, start, length) → Tensor ``` 与 [`Tensor.narrow()`](#torch.Tensor.narrow "torch.Tensor.narrow") 相同,只是返回副本而不是共享存储。 这主要用于稀疏张量,它们没有共享存储的窄方法。 用``dimemsion > self.sparse_dim()``调用``narrow_copy`将返回缩小了相关密集尺寸的副本,并相应地更新了``self.shape``。 @@ -2288,7 +2252,7 @@ narrow_copy(dimension, start, length) → Tensor¶ * * * ``` -ndimension() → int¶ +ndimension() → int ``` Alias for [`dim()`](#torch.Tensor.dim "torch.Tensor.dim") @@ -2296,7 +2260,7 @@ Alias for [`dim()`](#torch.Tensor.dim "torch.Tensor.dim") * * * ``` -ne(other) → Tensor¶ +ne(other) → Tensor ``` 参见 [`torch.ne()`](torch.html#torch.ne "torch.ne") @@ -2304,7 +2268,7 @@ ne(other) → Tensor¶ * * * ``` -ne_(other) → Tensor¶ +ne_(other) → Tensor ``` 就地版本的 [`ne()`](#torch.Tensor.ne "torch.Tensor.ne") @@ -2312,7 +2276,7 @@ ne_(other) → Tensor¶ * * * ``` -neg() → Tensor¶ +neg() → Tensor ``` 参见 [`torch.neg()`](torch.html#torch.neg "torch.neg") @@ -2320,7 +2284,7 @@ neg() → Tensor¶ * * * ``` -neg_() → Tensor¶ +neg_() → Tensor ``` 就地版本的 [`neg()`](#torch.Tensor.neg "torch.Tensor.neg") @@ -2328,7 +2292,7 @@ neg_() → Tensor¶ * * * ``` -nelement() → int¶ +nelement() → int ``` [`numel()`](#torch.Tensor.numel "torch.Tensor.numel") 的别名 @@ -2336,7 +2300,7 @@ nelement() → int¶ * * * ``` -nonzero() → LongTensor¶ +nonzero() → LongTensor ``` 参见 [`torch.nonzero()`](torch.html#torch.nonzero "torch.nonzero") @@ -2344,7 +2308,7 @@ nonzero() → LongTensor¶ * * * ``` -norm(p='fro', dim=None, keepdim=False, dtype=None)¶ +norm(p='fro', dim=None, keepdim=False, dtype=None) ``` 参见 [`torch.norm()`](torch.html#torch.norm "torch.norm") @@ -2352,7 +2316,7 @@ norm(p='fro', dim=None, keepdim=False, dtype=None)¶ * * * ``` -normal_(mean=0, std=1, *, generator=None) → Tensor¶ +normal_(mean=0, std=1, *, generator=None) → Tensor ``` 用由 [`mean`](torch.html#torch.mean "torch.mean") 和 [`std`](torch.html#torch.std "torch.std") 参数化的正态分布的元素样本填充`self`张量。 @@ -2360,7 +2324,7 @@ normal_(mean=0, std=1, *, generator=None) → Tensor¶ * * * ``` -numel() → int¶ +numel() → int ``` 参见 [`torch.numel()`](torch.html#torch.numel "torch.numel") @@ -2368,7 +2332,7 @@ numel() → int¶ * * * ``` -numpy() → numpy.ndarray¶ +numpy() → numpy.ndarray ``` 以 NumPy `ndarray`的形式返回`self`张量。 该张量和返回的`ndarray`共享相同的基础存储。 对`self`张量的更改将反映在`ndarray`中,反之亦然。 @@ -2376,7 +2340,7 @@ numpy() → numpy.ndarray¶ * * * ``` -orgqr(input2) → Tensor¶ +orgqr(input2) → Tensor ``` 参见 [`torch.orgqr()`](torch.html#torch.orgqr "torch.orgqr") @@ -2384,7 +2348,7 @@ orgqr(input2) → Tensor¶ * * * ``` -ormqr(input2, input3, left=True, transpose=False) → Tensor¶ +ormqr(input2, input3, left=True, transpose=False) → Tensor ``` 参见 [`torch.ormqr()`](torch.html#torch.ormqr "torch.ormqr") @@ -2392,16 +2356,16 @@ ormqr(input2, input3, left=True, transpose=False) → Tensor¶ * * * ``` -permute(*dims) → Tensor¶ +permute(*dims) → Tensor ``` 置换此张量的尺寸。 -Parameters +参数 -***尺寸** (_python:int ..._ )–所需的尺寸顺序 +***dims** (_python:int ..._ ) – 所需的维度顺序 -例 +例: ``` >>> x = torch.randn(2, 3, 5) @@ -2415,7 +2379,7 @@ torch.Size([5, 2, 3]) * * * ``` -pin_memory() → Tensor¶ +pin_memory() → Tensor ``` 将张量复制到固定的内存(如果尚未固定)。 @@ -2423,7 +2387,7 @@ pin_memory() → Tensor¶ * * * ``` -pinverse() → Tensor¶ +pinverse() → Tensor ``` 参见 [`torch.pinverse()`](torch.html#torch.pinverse "torch.pinverse") @@ -2431,7 +2395,7 @@ pinverse() → Tensor¶ * * * ``` -polygamma(n) → Tensor¶ +polygamma(n) → Tensor ``` 参见 [`torch.polygamma()`](torch.html#torch.polygamma "torch.polygamma") @@ -2439,7 +2403,7 @@ polygamma(n) → Tensor¶ * * * ``` -polygamma_(n) → Tensor¶ +polygamma_(n) → Tensor ``` 就地版本的 [`polygamma()`](#torch.Tensor.polygamma "torch.Tensor.polygamma") @@ -2447,7 +2411,7 @@ polygamma_(n) → Tensor¶ * * * ``` -pow(exponent) → Tensor¶ +pow(exponent) → Tensor ``` 参见 [`torch.pow()`](torch.html#torch.pow "torch.pow") @@ -2455,7 +2419,7 @@ pow(exponent) → Tensor¶ * * * ``` -pow_(exponent) → Tensor¶ +pow_(exponent) → Tensor ``` 就地版本的 [`pow()`](#torch.Tensor.pow "torch.Tensor.pow") @@ -2463,7 +2427,7 @@ pow_(exponent) → Tensor¶ * * * ``` -prod(dim=None, keepdim=False, dtype=None) → Tensor¶ +prod(dim=None, keepdim=False, dtype=None) → Tensor ``` 参见 [`torch.prod()`](torch.html#torch.prod "torch.prod") @@ -2471,14 +2435,14 @@ prod(dim=None, keepdim=False, dtype=None) → Tensor¶ * * * ``` -put_(indices, tensor, accumulate=False) → Tensor¶ +put_(indices, tensor, accumulate=False) → Tensor ``` 将 [`tensor`](torch.html#torch.tensor "torch.tensor") 中的元素复制到索引指定的位置。 为了建立索引,将`self`张量视为一维张量。 If `accumulate` is `True`, the elements in [`tensor`](torch.html#torch.tensor "torch.tensor") are added to `self`. If accumulate is `False`, the behavior is undefined if indices contain duplicate elements. -Parameters +参数 * **索引** (_LongTensor_ )–自身索引 @@ -2486,7 +2450,7 @@ Parameters * **accumulate** (_bool_) – whether to accumulate into self -Example: +例: ``` >>> src = torch.tensor([[4, 3, 5], @@ -2500,7 +2464,7 @@ tensor([[ 4, 9, 5], * * * ``` -qr(some=True) -> (Tensor, Tensor)¶ +qr(some=True) -> (Tensor, Tensor) ``` 参见 [`torch.qr()`](torch.html#torch.qr "torch.qr") @@ -2508,7 +2472,7 @@ qr(some=True) -> (Tensor, Tensor)¶ * * * ``` -qscheme() → torch.qscheme¶ +qscheme() → torch.qscheme ``` 返回给定 QTensor 的量化方案。 @@ -2516,7 +2480,7 @@ qscheme() → torch.qscheme¶ * * * ``` -q_scale() → float¶ +q_scale() → float ``` 给定一个通过线性(仿射)量化量化的张量,返回基础量化器()的比例尺。 @@ -2524,7 +2488,7 @@ q_scale() → float¶ * * * ``` -q_zero_point() → int¶ +q_zero_point() → int ``` 给定一个通过线性(仿射)量化量化的张量,返回基础量化器()的 zero_point。 @@ -2532,7 +2496,7 @@ q_zero_point() → int¶ * * * ``` -q_per_channel_scales() → Tensor¶ +q_per_channel_scales() → Tensor ``` 给定通过线性(仿射)每通道量化进行量化的张量,返回基础量化器的比例的张量。 它具有与张量的相应尺寸(来自 q_per_channel_axis)匹配的元素数量。 @@ -2540,7 +2504,7 @@ q_per_channel_scales() → Tensor¶ * * * ``` -q_per_channel_zero_points() → Tensor¶ +q_per_channel_zero_points() → Tensor ``` 给定一个通过线性(仿射)每通道量化量化的张量,返回基础量化器的 zero_points 张量。 它具有与张量的相应尺寸(来自 q_per_channel_axis)匹配的元素数量。 @@ -2548,7 +2512,7 @@ q_per_channel_zero_points() → Tensor¶ * * * ``` -q_per_channel_axis() → int¶ +q_per_channel_axis() → int ``` 给定通过线性(仿射)每通道量化量化的张量,返回在其上应用每通道量化的尺寸索引。 @@ -2556,7 +2520,7 @@ q_per_channel_axis() → int¶ * * * ``` -random_(from=0, to=None, *, generator=None) → Tensor¶ +random_(from=0, to=None, *, generator=None) → Tensor ``` 用从`[from, to - 1]`上的离散均匀分布采样的数字填充`self`张量。 如果未指定,则这些值通常仅受`self`张量的数据类型限制。 但是,对于浮点类型,如果未指定,范围将为`[0, 2^mantissa]`以确保每个值都是可表示的。 例如, <cite>torch.tensor(1,dtype = torch.double).random_()</cite>在`[0, 2^53]`中将是统一的。 @@ -2564,7 +2528,7 @@ random_(from=0, to=None, *, generator=None) → Tensor¶ * * * ``` -reciprocal() → Tensor¶ +reciprocal() → Tensor ``` 参见 [`torch.reciprocal()`](torch.html#torch.reciprocal "torch.reciprocal") @@ -2572,7 +2536,7 @@ reciprocal() → Tensor¶ * * * ``` -reciprocal_() → Tensor¶ +reciprocal_() → Tensor ``` 就地版本的 [`reciprocal()`](#torch.Tensor.reciprocal "torch.Tensor.reciprocal") @@ -2580,12 +2544,12 @@ reciprocal_() → Tensor¶ * * * ``` -record_stream(stream)¶ +record_stream(stream) ``` 确保在`stream`上排队的所有当前工作完成之前,张量存储器不会被其他张量重用。 -Note +注意 缓存分配器仅知道分配张量的流。 由于有了这种认识,它已经可以仅在一个流上正确管理张量的生命周期。 但是,如果在与原始流不同的流上使用张量,则分配器可能会意外地重用内存。 调用此方法可让分配器知道哪些流使用了张量。 @@ -2608,7 +2572,7 @@ hook(grad) -> Tensor or None 此函数返回带有方法`handle.remove()`的句柄,该方法可将钩子从模块中移除。 -Example: +例: ``` >>> v = torch.tensor([0., 0., 0.], requires_grad=True) @@ -2628,7 +2592,7 @@ Example: * * * ``` -remainder(divisor) → Tensor¶ +remainder(divisor) → Tensor ``` 参见 [`torch.remainder()`](torch.html#torch.remainder "torch.remainder") @@ -2636,7 +2600,7 @@ remainder(divisor) → Tensor¶ * * * ``` -remainder_(divisor) → Tensor¶ +remainder_(divisor) → Tensor ``` 就地版本的 [`remainder()`](#torch.Tensor.remainder "torch.Tensor.remainder") @@ -2644,7 +2608,7 @@ remainder_(divisor) → Tensor¶ * * * ``` -real() → Tensor¶ +real() → Tensor ``` 参见 [`torch.real()`](torch.html#torch.real "torch.real") @@ -2652,7 +2616,7 @@ real() → Tensor¶ * * * ``` -renorm(p, dim, maxnorm) → Tensor¶ +renorm(p, dim, maxnorm) → Tensor ``` 参见 [`torch.renorm()`](torch.html#torch.renorm "torch.renorm") @@ -2660,7 +2624,7 @@ renorm(p, dim, maxnorm) → Tensor¶ * * * ``` -renorm_(p, dim, maxnorm) → Tensor¶ +renorm_(p, dim, maxnorm) → Tensor ``` 就地版本的 [`renorm()`](#torch.Tensor.renorm "torch.Tensor.renorm") @@ -2668,22 +2632,22 @@ renorm_(p, dim, maxnorm) → Tensor¶ * * * ``` -repeat(*sizes) → Tensor¶ +repeat(*sizes) → Tensor ``` 沿指定尺寸重复此张量。 与 [`expand()`](#torch.Tensor.expand "torch.Tensor.expand") 不同,此功能复制张量的数据。 -Warning +警告 `torch.repeat()`的行为与 [numpy.repeat](https://docs.scipy.org/doc/numpy/reference/generated/numpy.repeat.html) 不同,但更类似于 [numpy.tile](https://docs.scipy.org/doc/numpy/reference/generated/numpy.tile.html) 。 对于类似于 <cite>numpy.repeat</cite> 的运算符,请参见 [`torch.repeat_interleave()`](torch.html#torch.repeat_interleave "torch.repeat_interleave") 。 -Parameters +参数 **大小**(_torch大小_ _或_ _python:int ..._ )–在每个维度上重复此张量的次数 -Example: +例: ``` >>> x = torch.tensor([1, 2, 3]) @@ -2700,7 +2664,7 @@ torch.Size([4, 2, 3]) * * * ``` -repeat_interleave(repeats, dim=None) → Tensor¶ +repeat_interleave(repeats, dim=None) → Tensor ``` 参见 [`torch.repeat_interleave()`](torch.html#torch.repeat_interleave "torch.repeat_interleave") 。 @@ -2711,25 +2675,25 @@ requires_grad 如果需要为此张量计算梯度,则为`True`,否则为`False`。 -Note +注意 需要为张量计算梯度的事实并不意味着将填充 [`grad`](autograd.html#torch.Tensor.grad "torch.Tensor.grad") 属性,有关更多详细信息,请参见 [`is_leaf`](autograd.html#torch.Tensor.is_leaf "torch.Tensor.is_leaf") 。 * * * ``` -requires_grad_(requires_grad=True) → Tensor¶ +requires_grad_(requires_grad=True) → Tensor ``` 更改 autograd 是否应记录该张量上的操作:适当地设置此张量的 [`requires_grad`](autograd.html#torch.Tensor.requires_grad "torch.Tensor.requires_grad") 属性。 返回此张量。 [`requires_grad_()`](#torch.Tensor.requires_grad_ "torch.Tensor.requires_grad_") 的主要用例是告诉 autograd 在 Tensor `tensor`上开始记录操作。 如果`tensor`具有`requires_grad=False`(因为它是通过 DataLoader 获得的,或者需要进行预处理或初始化),则`tensor.requires_grad_()`将其设置为使 autograd 将开始在`tensor`上记录操作。 -Parameters +参数 **require_grad** (_bool_ )–如果 autograd 应该在该张量上记录操作。 默认值:`True`。 -Example: +例: ``` >>> # Let's say we want to preprocess some saved weights and use @@ -2752,48 +2716,48 @@ tensor([-1.1007, 0.9853, -4.2316, -1.6606]) * * * ``` -reshape(*shape) → Tensor¶ +reshape(*shape) → Tensor ``` 返回具有与`self`相同的数据和元素数量但具有指定形状的张量。 如果`shape`与当前形状兼容,则此方法返回一个视图。 当可以返回视图时,请参见 [`torch.Tensor.view()`](#torch.Tensor.view "torch.Tensor.view") 。 参见 [`torch.reshape()`](torch.html#torch.reshape "torch.reshape") -Parameters +参数 **形状** (_python:ints 的元组_ _或_ _python:int ..._ )–所需的形状 * * * ``` -reshape_as(other) → Tensor¶ +reshape_as(other) → Tensor ``` 以与`other`相同的形状返回此张量。 `self.reshape_as(other)`等效于`self.reshape(other.sizes())`。 如果`other.sizes()`与当前形状兼容,则此方法返回视图。 何时可以返回视图,请参见 [`torch.Tensor.view()`](#torch.Tensor.view "torch.Tensor.view") 。 有关`reshape`的更多信息,请参见 [`reshape()`](torch.html#torch.reshape "torch.reshape") 。 -Parameters +参数 **其他** ([`torch.Tensor`](#torch.Tensor "torch.Tensor"))–结果张量具有与`other`相同的形状。 * * * ``` -resize_(*sizes) → Tensor¶ +resize_(*sizes) → Tensor ``` 将`self`张量调整为指定大小。 如果元素数量大于当前存储大小,那么将调整基础存储的大小以适合新的元素数量。 如果元素数较小,则基础存储不会更改。 现有元素将保留,但任何新内存均未初始化。 -Warning +警告 这是一种底层方法。 将存储重新解释为 C 连续的,而忽略当前步幅(除非目标大小等于当前大小,在这种情况下,张量保持不变)。 对于大多数目的,您将改为使用 [`view()`](#torch.Tensor.view "torch.Tensor.view") (检查连续性),或使用 [`reshape()`](#torch.Tensor.reshape "torch.Tensor.reshape") (如果需要,可复制数据)。 要使用自定义步幅就地更改大小,请参见 [`set_()`](#torch.Tensor.set_ "torch.Tensor.set_") 。 -Parameters +参数 **大小**(_torch大小_ _或_ _python:int ..._ )–所需大小 -Example: +例: ``` >>> x = torch.tensor([[1, 2], [3, 4], [5, 6]]) @@ -2806,7 +2770,7 @@ tensor([[ 1, 2], * * * ``` -resize_as_(tensor) → Tensor¶ +resize_as_(tensor) → Tensor ``` 将`self`张量调整为与指定的 [`tensor`](torch.html#torch.tensor "torch.tensor") 相同的大小。 这等效于`self.resize_(tensor.size())`。 @@ -2822,7 +2786,7 @@ retain_grad() * * * ``` -rfft(signal_ndim, normalized=False, onesided=True) → Tensor¶ +rfft(signal_ndim, normalized=False, onesided=True) → Tensor ``` 参见 [`torch.rfft()`](torch.html#torch.rfft "torch.rfft") @@ -2830,7 +2794,7 @@ rfft(signal_ndim, normalized=False, onesided=True) → Tensor¶ * * * ``` -roll(shifts, dims) → Tensor¶ +roll(shifts, dims) → Tensor ``` 参见 [`torch.roll()`](torch.html#torch.roll "torch.roll") @@ -2838,7 +2802,7 @@ roll(shifts, dims) → Tensor¶ * * * ``` -rot90(k, dims) → Tensor¶ +rot90(k, dims) → Tensor ``` 参见 [`torch.rot90()`](torch.html#torch.rot90 "torch.rot90") @@ -2846,7 +2810,7 @@ rot90(k, dims) → Tensor¶ * * * ``` -round() → Tensor¶ +round() → Tensor ``` 参见 [`torch.round()`](torch.html#torch.round "torch.round") @@ -2854,7 +2818,7 @@ round() → Tensor¶ * * * ``` -round_() → Tensor¶ +round_() → Tensor ``` 就地版本的 [`round()`](#torch.Tensor.round "torch.Tensor.round") @@ -2862,7 +2826,7 @@ round_() → Tensor¶ * * * ``` -rsqrt() → Tensor¶ +rsqrt() → Tensor ``` 参见 [`torch.rsqrt()`](torch.html#torch.rsqrt "torch.rsqrt") @@ -2870,7 +2834,7 @@ rsqrt() → Tensor¶ * * * ``` -rsqrt_() → Tensor¶ +rsqrt_() → Tensor ``` 就地版本的 [`rsqrt()`](#torch.Tensor.rsqrt "torch.Tensor.rsqrt") @@ -2878,7 +2842,7 @@ rsqrt_() → Tensor¶ * * * ``` -scatter(dim, index, source) → Tensor¶ +scatter(dim, index, source) → Tensor ``` [`torch.Tensor.scatter_()`](#torch.Tensor.scatter_ "torch.Tensor.scatter_") 的替代版本 @@ -2886,7 +2850,7 @@ scatter(dim, index, source) → Tensor¶ * * * ``` -scatter_(dim, index, src) → Tensor¶ +scatter_(dim, index, src) → Tensor ``` 将张量`src`中的所有值写入`index`张量中指定的索引处的`self`中。 对于`src`中的每个值,其输出索引由`dimension != dim`的`src`中的索引以及`dimension = dim`的`index`中的相应值指定。 @@ -2906,17 +2870,17 @@ self[i][j][index[i][j][k]] = src[i][j][k] # if dim == 2 此外,对于 [`gather()`](#torch.Tensor.gather "torch.Tensor.gather") ,`index`的值必须介于`0`和`self.size(dim) - 1`之间,且沿指定尺寸 [`dim`](#torch.Tensor.dim "torch.Tensor.dim") 必须是唯一的。 -Parameters +参数 -* **暗淡的** (_python:int_ )–沿其索引的轴 +* **dim** (_python:int_ ) – 沿其索引的轴 -* **索引** (_LongTensor_ )–要散布的元素的索引可以为空或 src 的大小相同。 如果为空,则操作返回标识 +* **index** (_LongTensor_ ) – 要散布的元素的索引可以为空或 src 的大小相同。 如果为空,则操作返回标识 -* **src** ([_tensor_](#torch.Tensor "torch.Tensor"))–要散布的源元素,如果未指定<cite>值</cite> +* **src** ([_tensor_](#torch.Tensor "torch.Tensor")) – 要散布的源元素,如果未指定_值_ -* **值** (_python:float_ )–要分散的源元素,如果未指定 <cite>src</cite> +* **value** (_python:float_ ) – 要分散的源元素,如果未指定_src_ -Example: +例: ``` >>> x = torch.rand(2, 5) @@ -2938,7 +2902,7 @@ tensor([[ 0.0000, 0.0000, 1.2300, 0.0000], * * * ``` -scatter_add_(dim, index, other) → Tensor¶ +scatter_add_(dim, index, other) → Tensor ``` 将张量`other`中的所有值添加到`index`张量中指定的索引处的`self`中,其方式与 [`scatter_()`](#torch.Tensor.scatter_ "torch.Tensor.scatter_") 相似。 对于`other`中的每个值,将其添加到`self`中的索引,该索引由`dimension != dim`中的`other`中的索引和`dimension = dim`中的`index`中的对应值指定。 @@ -2954,19 +2918,19 @@ self[i][j][index[i][j][k]] += other[i][j][k] # if dim == 2 `self`,`index`和`other`应具有相同的尺寸数。 还要求对于所有尺寸`d`均为`index.size(d) <= other.size(d)`,并且对于所有尺寸`d != dim`均要求`index.size(d) <= self.size(d)`。 -Note +注意 -When using the CUDA backend, this operation may induce nondeterministic behaviour that is not easily switched off. Please see the notes on [Reproducibility](notes/randomness.html) for background. +When using the CUDA backend, this operation may induce nondeterministic behaviour that is not easily switched off. Please see the 注意s on [Reproducibility](注意s/randomness.html) for background. -Parameters +参数 * **dim** (_python:int_) – the axis along which to index -* **索引** (_LongTensor_ )–分散和添加元素的索引,可以为空或 src 大小相同。 为空时,该操作将返回标识。 +* **index** (_LongTensor_ ) – 分散和添加元素的索引,可以为空或 src 大小相同。 为空时,该操作将返回标识。 -* **其他** ([_tensor_](#torch.Tensor "torch.Tensor"))–分散和添加的源元素 +* **other** ([_tensor_](#torch.Tensor "torch.Tensor")) – 分散和添加的源元素 -Example: +例: ``` >>> x = torch.rand(2, 5) @@ -2983,7 +2947,7 @@ tensor([[1.7404, 1.2009, 1.9154, 1.3806, 1.8328], * * * ``` -scatter_add(dim, index, source) → Tensor¶ +scatter_add(dim, index, source) → Tensor ``` [`torch.Tensor.scatter_add_()`](#torch.Tensor.scatter_add_ "torch.Tensor.scatter_add_") 的替代版本 @@ -2991,32 +2955,32 @@ scatter_add(dim, index, source) → Tensor¶ * * * ``` -select(dim, index) → Tensor¶ +select(dim, index) → Tensor ``` 沿选定维度在给定索引处切片`self`张量。 该函数返回一个张量,其中给定尺寸被移除。 -Parameters +参数 -* **暗淡的** (_python:int_ )–切片的尺寸 +* **dim** (_python:int_ )–切片的尺寸 * **索引** (_python:int_ )–要选择的索引 -Note +注意 [`select()`](#torch.Tensor.select "torch.Tensor.select") 相当于切片。 例如,`tensor.select(0, index)`等效于`tensor[index]`,`tensor.select(2, index)`等效于`tensor[:,:,index]`。 * * * ``` -set_(source=None, storage_offset=0, size=None, stride=None) → Tensor¶ +set_(source=None, storage_offset=0, size=None, stride=None) → Tensor ``` 设置基础存储空间,大小和跨度。 如果`source`是张量,则`self`张量将与`source`共享相同的存储空间并具有相同的大小和跨度。 一个张量中元素的变化将反映在另一个张量中。 如果`source`是`Storage`,则该方法设置基础存储,偏移,大小和跨度。 -Parameters +参数 * **源** ([_tensor_](#torch.Tensor "torch.Tensor") _或_ _存储器_)–使用的张量或存储器 @@ -3029,7 +2993,7 @@ Parameters * * * ``` -share_memory_()¶ +share_memory_() ``` 将基础存储移动到共享内存。 @@ -3039,7 +3003,7 @@ share_memory_()¶ * * * ``` -short() → Tensor¶ +short() → Tensor ``` `self.short()`等效于`self.to(torch.int16)`。 参见 [`to()`](#torch.Tensor.to "torch.Tensor.to") 。 @@ -3047,7 +3011,7 @@ short() → Tensor¶ * * * ``` -sigmoid() → Tensor¶ +sigmoid() → Tensor ``` 参见 [`torch.sigmoid()`](torch.html#torch.sigmoid "torch.sigmoid") @@ -3055,7 +3019,7 @@ sigmoid() → Tensor¶ * * * ``` -sigmoid_() → Tensor¶ +sigmoid_() → Tensor ``` 就地版本的 [`sigmoid()`](#torch.Tensor.sigmoid "torch.Tensor.sigmoid") @@ -3063,7 +3027,7 @@ sigmoid_() → Tensor¶ * * * ``` -sign() → Tensor¶ +sign() → Tensor ``` 参见 [`torch.sign()`](torch.html#torch.sign "torch.sign") @@ -3071,7 +3035,7 @@ sign() → Tensor¶ * * * ``` -sign_() → Tensor¶ +sign_() → Tensor ``` 就地版本的 [`sign()`](#torch.Tensor.sign "torch.Tensor.sign") @@ -3079,7 +3043,7 @@ sign_() → Tensor¶ * * * ``` -sin() → Tensor¶ +sin() → Tensor ``` 参见 [`torch.sin()`](torch.html#torch.sin "torch.sin") @@ -3087,7 +3051,7 @@ sin() → Tensor¶ * * * ``` -sin_() → Tensor¶ +sin_() → Tensor ``` 就地版本的 [`sin()`](#torch.Tensor.sin "torch.Tensor.sin") @@ -3095,7 +3059,7 @@ sin_() → Tensor¶ * * * ``` -sinh() → Tensor¶ +sinh() → Tensor ``` 参见 [`torch.sinh()`](torch.html#torch.sinh "torch.sinh") @@ -3103,7 +3067,7 @@ sinh() → Tensor¶ * * * ``` -sinh_() → Tensor¶ +sinh_() → Tensor ``` 就地版本的 [`sinh()`](#torch.Tensor.sinh "torch.Tensor.sinh") @@ -3111,12 +3075,12 @@ sinh_() → Tensor¶ * * * ``` -size() → torch.Size¶ +size() → torch.Size ``` 返回`self`张量的大小。 返回的值是`tuple`的子类。 -Example: +例: ``` >>> torch.empty(3, 4, 5).size() @@ -3127,7 +3091,7 @@ torch.Size([3, 4, 5]) * * * ``` -slogdet() -> (Tensor, Tensor)¶ +slogdet() -> (Tensor, Tensor) ``` 参见 [`torch.slogdet()`](torch.html#torch.slogdet "torch.slogdet") @@ -3135,7 +3099,7 @@ slogdet() -> (Tensor, Tensor)¶ * * * ``` -solve(A) → Tensor, Tensor¶ +solve(A) → Tensor, Tensor ``` 参见 [`torch.solve()`](torch.html#torch.solve "torch.solve") @@ -3143,7 +3107,7 @@ solve(A) → Tensor, Tensor¶ * * * ``` -sort(dim=-1, descending=False) -> (Tensor, LongTensor)¶ +sort(dim=-1, descending=False) -> (Tensor, LongTensor) ``` 参见 [`torch.sort()`](torch.html#torch.sort "torch.sort") @@ -3151,7 +3115,7 @@ sort(dim=-1, descending=False) -> (Tensor, LongTensor)¶ * * * ``` -split(split_size, dim=0)¶ +split(split_size, dim=0) ``` 参见 [`torch.split()`](torch.html#torch.split "torch.split") @@ -3159,18 +3123,18 @@ split(split_size, dim=0)¶ * * * ``` -sparse_mask(input, mask) → Tensor¶ +sparse_mask(input, mask) → Tensor ``` 返回一个新的 SparseTensor,其 Tensor `input`中的值被`mask`的索引过滤,并且值被忽略。 `input`和`mask`必须具有相同的形状。 -Parameters +参数 -* **输入** ([_tensor_](#torch.Tensor "torch.Tensor"))–输入张量 +* **input** ([_tensor_](#torch.Tensor "torch.Tensor"))–输入张量 -* **遮罩** (_SparseTensor_ )–我们根据其索引过滤`input`的 SparseTensor +* **mask** (_SparseTensor_ )–我们根据其索引过滤`input`的 SparseTensor -Example: +例: ``` >>> nnz = 5 @@ -3202,7 +3166,7 @@ tensor(indices=tensor([[0, 0, 0, 2], * * * ``` -sparse_dim() → int¶ +sparse_dim() → int ``` 如果`self`是稀疏的 COO 张量(即`torch.sparse_coo`布局),则返回稀疏维度的数量。 否则,将引发错误。 @@ -3212,7 +3176,7 @@ sparse_dim() → int¶ * * * ``` -sqrt() → Tensor¶ +sqrt() → Tensor ``` 参见 [`torch.sqrt()`](torch.html#torch.sqrt "torch.sqrt") @@ -3220,7 +3184,7 @@ sqrt() → Tensor¶ * * * ``` -sqrt_() → Tensor¶ +sqrt_() → Tensor ``` 就地版本的 [`sqrt()`](#torch.Tensor.sqrt "torch.Tensor.sqrt") @@ -3228,7 +3192,7 @@ sqrt_() → Tensor¶ * * * ``` -squeeze(dim=None) → Tensor¶ +squeeze(dim=None) → Tensor ``` 参见 [`torch.squeeze()`](torch.html#torch.squeeze "torch.squeeze") @@ -3236,7 +3200,7 @@ squeeze(dim=None) → Tensor¶ * * * ``` -squeeze_(dim=None) → Tensor¶ +squeeze_(dim=None) → Tensor ``` 就地版本的 [`squeeze()`](#torch.Tensor.squeeze "torch.Tensor.squeeze") @@ -3244,7 +3208,7 @@ squeeze_(dim=None) → Tensor¶ * * * ``` -std(dim=None, unbiased=True, keepdim=False) → Tensor¶ +std(dim=None, unbiased=True, keepdim=False) → Tensor ``` 参见 [`torch.std()`](torch.html#torch.std "torch.std") @@ -3252,19 +3216,19 @@ std(dim=None, unbiased=True, keepdim=False) → Tensor¶ * * * ``` -stft(n_fft, hop_length=None, win_length=None, window=None, center=True, pad_mode='reflect', normalized=False, onesided=True)¶ +stft(n_fft, hop_length=None, win_length=None, window=None, center=True, pad_mode='reflect', normalized=False, onesided=True) ``` 参见 [`torch.stft()`](torch.html#torch.stft "torch.stft") -Warning +警告 此功能在版本 0.4.1 更改了签名。 使用前一个签名进行调用可能会导致错误或返回错误的结果。 * * * ``` -storage() → torch.Storage¶ +storage() → torch.Storage ``` 返回基础存储。 @@ -3272,12 +3236,12 @@ storage() → torch.Storage¶ * * * ``` -storage_offset() → int¶ +storage_offset() → int ``` 根据存储元素的数量(不是字节),返回基础存储中的`self`张量偏移量。 -Example: +例: ``` >>> x = torch.tensor([1, 2, 3, 4, 5]) @@ -3291,7 +3255,7 @@ Example: * * * ``` -storage_type() → type¶ +storage_type() → type ``` 返回基础存储的类型。 @@ -3299,18 +3263,18 @@ storage_type() → type¶ * * * ``` -stride(dim) → tuple or int¶ +stride(dim) → tuple or int ``` 返回`self`张量的步幅。 跨度是在指定尺寸 [`dim`](#torch.Tensor.dim "torch.Tensor.dim") 中从一个元素跳至下一元素所需的跳跃。 当未传递任何参数时,将返回所有跨度的元组。否则,将返回整数值作为特定维度 [`dim`](#torch.Tensor.dim "torch.Tensor.dim") 中的跨度。 -Parameters +参数 -**暗淡的** (_python:int_ _,_ _可选_)–需要跨度的所需尺寸 +**dim** (_python:int_ _,_ _可选_)– 需要跨度的所需尺寸 -Example: +例: ``` >>> x = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]) @@ -3326,17 +3290,17 @@ Example: * * * ``` -sub(value, other) → Tensor¶ +sub(value, other) → Tensor ``` 从`self`张量中减去标量或张量。 如果同时指定了`value`和`other`,则在使用前`other`的每个元素都会按`value`缩放。 -当`other`是张量时,`other`的形状必须是[可广播的](notes/broadcasting.html#broadcasting-semantics),并具有基础张量的形状。 +当`other`是张量时,`other`的形状必须是[可广播的](注意s/broadcasting.html#broadcasting-semantics),并具有基础张量的形状。 * * * ``` -sub_(x) → Tensor¶ +sub_(x) → Tensor ``` 就地版本的 [`sub()`](#torch.Tensor.sub "torch.Tensor.sub") @@ -3344,7 +3308,7 @@ sub_(x) → Tensor¶ * * * ``` -sum(dim=None, keepdim=False, dtype=None) → Tensor¶ +sum(dim=None, keepdim=False, dtype=None) → Tensor ``` 参见 [`torch.sum()`](torch.html#torch.sum "torch.sum") @@ -3352,19 +3316,19 @@ sum(dim=None, keepdim=False, dtype=None) → Tensor¶ * * * ``` -sum_to_size(*size) → Tensor¶ +sum_to_size(*size) → Tensor ``` 将`this`张量与 [`size`](#torch.Tensor.size "torch.Tensor.size") 相加。 [`size`](#torch.Tensor.size "torch.Tensor.size") 必须可广播到`this`张量大小。 -Parameters +参数 **大小** (_python:int ..._ )–定义输出张量形状的整数序列。 * * * ``` -svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)¶ +svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor) ``` 参见 [`torch.svd()`](torch.html#torch.svd "torch.svd") @@ -3372,7 +3336,7 @@ svd(some=True, compute_uv=True) -> (Tensor, Tensor, Tensor)¶ * * * ``` -symeig(eigenvectors=False, upper=True) -> (Tensor, Tensor)¶ +symeig(eigenvectors=False, upper=True) -> (Tensor, Tensor) ``` 参见 [`torch.symeig()`](torch.html#torch.symeig "torch.symeig") @@ -3380,7 +3344,7 @@ symeig(eigenvectors=False, upper=True) -> (Tensor, Tensor)¶ * * * ``` -t() → Tensor¶ +t() → Tensor ``` 参见 [`torch.t()`](torch.html#torch.t "torch.t") @@ -3388,7 +3352,7 @@ t() → Tensor¶ * * * ``` -t_() → Tensor¶ +t_() → Tensor ``` 就地版本的 [`t()`](#torch.Tensor.t "torch.Tensor.t") @@ -3396,12 +3360,12 @@ t_() → Tensor¶ * * * ``` -to(*args, **kwargs) → Tensor¶ +to(*args, **kwargs) → Tensor ``` 执行 Tensor dtype 和/或设备转换。 [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") 和 [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") 是从`self.to(*args, **kwargs)`的论点推论出来的。 -Note +注意 如果`self`张量已经具有正确的 [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") 和 [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") ,则返回`self`。 否则,返回的张量是`self`与所需 [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") 和 [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") 的副本。 @@ -3431,7 +3395,7 @@ to(other, non_blocking=False, copy=False) → Tensor 返回与张量`other`相同的 [`torch.dtype`](tensor_attributes.html#torch.torch.dtype "torch.torch.dtype") 和 [`torch.device`](tensor_attributes.html#torch.torch.device "torch.torch.device") 的张量。 当`non_blocking`时,如果可能,尝试相对于主机进行异步转换,例如,将具有固定内存的 CPU 张量转换为 CUDA 张量。 设置`copy`时,即使张量已经与所需的转换匹配,也会创建新的张量。 -Example: +例: ``` >>> tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu @@ -3458,7 +3422,7 @@ tensor([[-0.5044, 0.0005], * * * ``` -to_mkldnn() → Tensor¶ +to_mkldnn() → Tensor ``` 返回`torch.mkldnn`布局中的张量的副本。 @@ -3466,7 +3430,7 @@ to_mkldnn() → Tensor¶ * * * ``` -take(indices) → Tensor¶ +take(indices) → Tensor ``` 参见 [`torch.take()`](torch.html#torch.take "torch.take") @@ -3474,7 +3438,7 @@ take(indices) → Tensor¶ * * * ``` -tan() → Tensor¶ +tan() → Tensor ``` 参见 [`torch.tan()`](torch.html#torch.tan "torch.tan") @@ -3482,7 +3446,7 @@ tan() → Tensor¶ * * * ``` -tan_() → Tensor¶ +tan_() → Tensor ``` 就地版本的 [`tan()`](#torch.Tensor.tan "torch.Tensor.tan") @@ -3490,7 +3454,7 @@ tan_() → Tensor¶ * * * ``` -tanh() → Tensor¶ +tanh() → Tensor ``` 参见 [`torch.tanh()`](torch.html#torch.tanh "torch.tanh") @@ -3498,7 +3462,7 @@ tanh() → Tensor¶ * * * ``` -tanh_() → Tensor¶ +tanh_() → Tensor ``` 就地版本的 [`tanh()`](#torch.Tensor.tanh "torch.Tensor.tanh") @@ -3506,7 +3470,7 @@ tanh_() → Tensor¶ * * * ``` -tolist()¶ +tolist() ``` ” tolist()->列表或编号 @@ -3530,7 +3494,7 @@ This operation is not differentiable. * * * ``` -topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)¶ +topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor) ``` 参见 [`torch.topk()`](torch.html#torch.topk "torch.topk") @@ -3538,16 +3502,16 @@ topk(k, dim=None, largest=True, sorted=True) -> (Tensor, LongTensor)¶ * * * ``` -to_sparse(sparseDims) → Tensor¶ +to_sparse(sparseDims) → Tensor ``` 返回张量的稀疏副本。 PyTorch 支持[坐标格式](sparse.html#sparse-docs)的稀疏张量。 -Parameters +参数 -**sparseDims** (_python:int_ _,_ _可选_)–新稀疏张量中包含的稀疏维数 +**sparseDims** (_python:int_ _,_ _可选_)– 新稀疏张量中包含的稀疏维数 -Example: +例: ``` >>> d = torch.tensor([[0, 0, 0], [9, 0, 10], [0, 0, 0]]) @@ -3570,7 +3534,7 @@ tensor(indices=tensor([[1]]), * * * ``` -trace() → Tensor¶ +trace() → Tensor ``` 参见 [`torch.trace()`](torch.html#torch.trace "torch.trace") @@ -3578,7 +3542,7 @@ trace() → Tensor¶ * * * ``` -transpose(dim0, dim1) → Tensor¶ +transpose(dim0, dim1) → Tensor ``` 参见 [`torch.transpose()`](torch.html#torch.transpose "torch.transpose") @@ -3586,7 +3550,7 @@ transpose(dim0, dim1) → Tensor¶ * * * ``` -transpose_(dim0, dim1) → Tensor¶ +transpose_(dim0, dim1) → Tensor ``` 就地版本的 [`transpose()`](#torch.Tensor.transpose "torch.Tensor.transpose") @@ -3594,7 +3558,7 @@ transpose_(dim0, dim1) → Tensor¶ * * * ``` -triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor)¶ +triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor, Tensor) ``` 参见 [`torch.triangular_solve()`](torch.html#torch.triangular_solve "torch.triangular_solve") @@ -3602,7 +3566,7 @@ triangular_solve(A, upper=True, transpose=False, unitriangular=False) -> (Tensor * * * ``` -tril(k=0) → Tensor¶ +tril(k=0) → Tensor ``` 参见 [`torch.tril()`](torch.html#torch.tril "torch.tril") @@ -3610,7 +3574,7 @@ tril(k=0) → Tensor¶ * * * ``` -tril_(k=0) → Tensor¶ +tril_(k=0) → Tensor ``` 就地版本的 [`tril()`](#torch.Tensor.tril "torch.Tensor.tril") @@ -3618,7 +3582,7 @@ tril_(k=0) → Tensor¶ * * * ``` -triu(k=0) → Tensor¶ +triu(k=0) → Tensor ``` 参见 [`torch.triu()`](torch.html#torch.triu "torch.triu") @@ -3626,7 +3590,7 @@ triu(k=0) → Tensor¶ * * * ``` -triu_(k=0) → Tensor¶ +triu_(k=0) → Tensor ``` 就地版本的 [`triu()`](#torch.Tensor.triu "torch.Tensor.triu") @@ -3634,7 +3598,7 @@ triu_(k=0) → Tensor¶ * * * ``` -trunc() → Tensor¶ +trunc() → Tensor ``` 参见 [`torch.trunc()`](torch.html#torch.trunc "torch.trunc") @@ -3642,7 +3606,7 @@ trunc() → Tensor¶ * * * ``` -trunc_() → Tensor¶ +trunc_() → Tensor ``` 就地版本的 [`trunc()`](#torch.Tensor.trunc "torch.Tensor.trunc") @@ -3650,39 +3614,39 @@ trunc_() → Tensor¶ * * * ``` -type(dtype=None, non_blocking=False, **kwargs) → str or Tensor¶ +type(dtype=None, non_blocking=False, **kwargs) → str or Tensor ``` -如果未提供 <cite>dtype</cite> ,则返回类型,否则将该对象强制转换为指定的类型。 +如果未提供_dtype_; ,则返回类型,否则将该对象强制转换为指定的类型。 如果它已经是正确的类型,则不执行任何复制,并返回原始对象。 -Parameters +参数 -* **dtype** (_python:type_ _或_ _字符串_)–所需类型 +* **dtype** (_python:type_ _或_ _字符串_)– 所需类型 -* **non_blocking** (_bool_ )–如果`True`,并且源位于固定内存中,而目标位于 GPU 上,反之亦然,则相对于主机异步执行复制。 否则,该参数无效。 +* **non_blocking** (_bool_ ) – 如果`True`,并且源位于固定内存中,而目标位于 GPU 上,反之亦然,则相对于主机异步执行复制。 否则,该参数无效。 -* ****** –为兼容起见,可以包含键`async`来代替`non_blocking`参数。 不推荐使用`async` arg。 +* ****kwargs** – 为兼容起见,可以包含键`async`来代替`non_blocking`参数。 不推荐使用`async` arg。 * * * ``` -type_as(tensor) → Tensor¶ +type_as(tensor) → Tensor ``` 将此张量转换为给定张量的类型。 如果张量已经是正确的类型,则这是无操作的。 相当于`self.type(tensor.type())` -Parameters +参数 **张量** ([_tensor_](#torch.Tensor "torch.Tensor"))–具有所需类型的张量 * * * ``` -unbind(dim=0) → seq¶ +unbind(dim=0) → seq ``` 参见 [`torch.unbind()`](torch.html#torch.unbind "torch.unbind") @@ -3690,26 +3654,26 @@ unbind(dim=0) → seq¶ * * * ``` -unfold(dimension, size, step) → Tensor¶ +unfold(dimension, size, step) → Tensor ``` 返回一个张量,该张量包含`self`张量中尺寸为`dimension`的所有大小为 [`size`](#torch.Tensor.size "torch.Tensor.size") 的切片。 两个切片之间的步长由`step`给出。 -如果 <cite>sizeim</cite> 是`self`的尺寸`dimension`的大小,则返回张量中`dimension`的尺寸将是<cite>(sizeim-size)/步长+ 1</cite> 。 +如果 _sizedim_ 是`self`的尺寸`dimension`的大小,则返回张量中`dimension`的尺寸将是(_sizeim-size_)/_step_+ 1 。 在返回的张量中附加了尺寸为 [`size`](#torch.Tensor.size "torch.Tensor.size") 的附加尺寸。 -Parameters +参数 -* **尺寸** (_python:int_ )–发生展开的尺寸 +* **dimension** (_python:int_ )–发生展开的尺寸 -* **大小** (_python:int_ )–展开的每个切片的大小 +* **size** (_python:int_ )–展开的每个切片的大小 -* **步骤** (_python:int_ )–每个切片之间的步骤 +* **step** (_python:int_ )–每个切片之间的步骤 -Example: +例: ``` >>> x = torch.arange(1., 8) @@ -3732,7 +3696,7 @@ tensor([[ 1., 2.], * * * ``` -uniform_(from=0, to=1) → Tensor¶ +uniform_(from=0, to=1) → Tensor ``` 用从连续均匀分布中采样的数字填充`self`张量: @@ -3742,7 +3706,7 @@ uniform_(from=0, to=1) → Tensor¶ * * * ``` -unique(sorted=True, return_inverse=False, return_counts=False, dim=None)¶ +unique(sorted=True, return_inverse=False, return_counts=False, dim=None) ``` 返回输入张量的唯一元素。 @@ -3752,7 +3716,7 @@ unique(sorted=True, return_inverse=False, return_counts=False, dim=None)¶ * * * ``` -unique_consecutive(return_inverse=False, return_counts=False, dim=None)¶ +unique_consecutive(return_inverse=False, return_counts=False, dim=None) ``` 从每个连续的等效元素组中除去除第一个元素外的所有元素。 @@ -3762,7 +3726,7 @@ unique_consecutive(return_inverse=False, return_counts=False, dim=None)¶ * * * ``` -unsqueeze(dim) → Tensor¶ +unsqueeze(dim) → Tensor ``` 参见 [`torch.unsqueeze()`](torch.html#torch.unsqueeze "torch.unsqueeze") @@ -3770,7 +3734,7 @@ unsqueeze(dim) → Tensor¶ * * * ``` -unsqueeze_(dim) → Tensor¶ +unsqueeze_(dim) → Tensor ``` 就地版本的 [`unsqueeze()`](#torch.Tensor.unsqueeze "torch.Tensor.unsqueeze") @@ -3778,21 +3742,21 @@ unsqueeze_(dim) → Tensor¶ * * * ``` -values() → Tensor¶ +values() → Tensor ``` 如果`self`是稀疏的 COO 张量(即`torch.sparse_coo`布局),则返回包含值张量的视图。 否则,将引发错误。 另请参见 [`Tensor.indices()`](#torch.Tensor.indices "torch.Tensor.indices") 。 -Note +注意 This method can only be called on a coalesced sparse tensor. See `Tensor.coalesce()` for details. * * * ``` -var(dim=None, unbiased=True, keepdim=False) → Tensor¶ +var(dim=None, unbiased=True, keepdim=False) → Tensor ``` 参见 [`torch.var()`](torch.html#torch.var "torch.var") @@ -3800,7 +3764,7 @@ var(dim=None, unbiased=True, keepdim=False) → Tensor¶ * * * ``` -view(*shape) → Tensor¶ +view(*shape) → Tensor ``` 返回具有与`self`张量相同的数据但具有不同`shape`的新张量。 @@ -3811,11 +3775,11 @@ view(*shape) → Tensor¶ 否则,需要先调用 [`contiguous()`](#torch.Tensor.contiguous "torch.Tensor.contiguous") 才能查看张量。 另请参见: [`reshape()`](torch.html#torch.reshape "torch.reshape") ,如果形状兼容则返回一个视图,否则复制(相当于调用 [`contiguous()`](#torch.Tensor.contiguous "torch.Tensor.contiguous"))。 -Parameters +参数 **形状**(_torch大小_ _或_ _python:int ..._ )–所需大小 -Example: +例: ``` >>> x = torch.randn(4, 4) @@ -3845,21 +3809,21 @@ False * * * ``` -view_as(other) → Tensor¶ +view_as(other) → Tensor ``` 将此张量查看为与`other`相同的大小。 `self.view_as(other)`等效于`self.view(other.size())`。 有关`view`的更多信息,请参见 [`view()`](#torch.Tensor.view "torch.Tensor.view") 。 -Parameters +参数 **other** ([`torch.Tensor`](#torch.Tensor "torch.Tensor")) – The result tensor has the same size as `other`. * * * ``` -where(condition, y) → Tensor¶ +where(condition, y) → Tensor ``` `self.where(condition, y)`等效于`torch.where(condition, self, y)`。 参见 [`torch.where()`](torch.html#torch.where "torch.where") @@ -3867,7 +3831,7 @@ where(condition, y) → Tensor¶ * * * ``` -zero_() → Tensor¶ +zero_() → Tensor ``` 用零填充`self`张量。 @@ -3875,7 +3839,7 @@ zero_() → Tensor¶ * * * ``` -class torch.BoolTensor¶ +class torch.BoolTensor ``` 以下方法是 [`torch.BoolTensor`](#torch.BoolTensor "torch.BoolTensor") 独有的。 @@ -3883,7 +3847,7 @@ class torch.BoolTensor¶ * * * ``` -all()¶ +all() ``` * * * @@ -3894,7 +3858,7 @@ all() → bool 如果张量中的所有元素均为 True,则返回 True,否则返回 False。 -Example: +例: ``` >>> a = torch.rand(1, 2).bool() @@ -3915,15 +3879,15 @@ all(dim, keepdim=False, out=None) → Tensor 如果`keepdim`为`True`,则输出张量的大小与`input`相同,但尺寸为`dim`的大小为 1。否则,将压缩`dim`(请参见 [`torch.squeeze()`](torch.html#torch.squeeze "torch.squeeze")),导致输出张量的尺寸比`input`小 1。 -Parameters +参数 -* **暗淡的** (_python:int_ )–缩小的尺寸 +* **dim** (_python:int_ ) – 缩小的尺寸 -* **keepdim** (_bool_ )–输出张量是否保留`dim` +* **keepdim** (_bool_ ) – 输出张量是否保留`dim` -* **out** ([_tensor_](#torch.Tensor "torch.Tensor") _,_ _可选_)–输出张量 +* **out** ([_tensor_](#torch.Tensor "torch.Tensor") _,_ _可选_)– 输出的张量 -Example: +例: ``` >>> a = torch.rand(4, 2).bool() @@ -3942,7 +3906,7 @@ tensor([ True, False], dtype=torch.bool) * * * ``` -any()¶ +any() ``` * * * @@ -3953,7 +3917,7 @@ any() → bool 如果张量中的任何元素为 True,则返回 True,否则为 False。 -Example: +例: ``` >>> a = torch.rand(1, 2).bool() @@ -3972,17 +3936,17 @@ any(dim, keepdim=False, out=None) → Tensor 如果张量的每一行中给定维度`dim`中的任何元素为 True,则返回 True,否则为 False。 -If `keepdim` is `True`, the output tensor is of the same size as `input` except in the dimension `dim` where it is of size 1. Otherwise, `dim` is squeezed (see [`torch.squeeze()`](torch.html#torch.squeeze "torch.squeeze")), resulting in the output tensor having 1 fewer dimension than `input`. +如果`keepdim`为`True`,则输出张量的大小与`input`相同,但尺寸为`dim`的大小为 1。否则,将压缩`dim`(请参见 [`torch.squeeze()`](torch.html#torch.squeeze "torch.squeeze")),导致输出张量的尺寸比`input`小 1。 -Parameters +参数 -* **dim** (_python:int_) – the dimension to reduce +* **dim** (_python:int_) – 缩小的尺寸 -* **keepdim** (_bool_) – whether the output tensor has `dim` retained or not +* **keepdim** (_bool_) – 输出张量是否保留`dim` -* **out** ([_Tensor_](#torch.Tensor "torch.Tensor")_,_ _optional_) – the output tensor +* **out** ([_Tensor_](#torch.Tensor "torch.Tensor")_,_ _optional_) – 输出的张量 -Example: +例: ``` >>> a = torch.randn(4, 2) < 0