# 命名为 Tensors 操作员范围

> 原文： [https://pytorch.org/docs/stable/name_inference.html](https://pytorch.org/docs/stable/name_inference.html)

请首先阅读[命名张量](named_tensor.html#named-tensors-doc)，以了解命名张量。

本文档是_名称推断_的参考，HTH1 是一个定义张量命名方式的过程：

1.  使用名称提供其他自动运行时正确性检查

2.  将名称从输入张量传播到输出张量

以下是命名张量及其关联的名称推断规则支持的所有操作的列表。

如果此处未列出操作，但对您的用例有帮助，请[搜索问题是否已提交](https://github.com/pytorch/pytorch/issues?q=is%3Aopen+is%3Aissue+label%3A%22module%3A+named+tensor%22)，否则请[提交一个问题](https://github.com/pytorch/pytorch/issues/new/choose)。

警告

命名的张量 API 是实验性的，随时可能更改。

<caption>Supported Operations</caption>

| API | 名称推断规则 |
| --- | --- |
| [`Tensor.abs()`](tensors.html#torch.Tensor.abs "torch.Tensor.abs") ， [`torch.abs()`](torch.html#torch.abs "torch.abs") | [保留输入名称](#keeps-input-names-doc) |
| [`Tensor.abs_()`](tensors.html#torch.Tensor.abs_ "torch.Tensor.abs_") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.acos()`](tensors.html#torch.Tensor.acos "torch.Tensor.acos") ， [`torch.acos()`](torch.html#torch.acos "torch.acos") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.acos_()`](tensors.html#torch.Tensor.acos_ "torch.Tensor.acos_") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.add()`](tensors.html#torch.Tensor.add "torch.Tensor.add") ， [`torch.add()`](torch.html#torch.add "torch.add") | [统一输入](#unifies-names-from-inputs-doc)的名称 |
| [`Tensor.add_()`](tensors.html#torch.Tensor.add_ "torch.Tensor.add_") | [Unifies names from inputs](#unifies-names-from-inputs-doc) |
| [`Tensor.addmm()`](tensors.html#torch.Tensor.addmm "torch.Tensor.addmm") ， [`torch.addmm()`](torch.html#torch.addmm "torch.addmm") | [缩小暗淡](#contracts-away-dims-doc) |
| [`Tensor.addmm_()`](tensors.html#torch.Tensor.addmm_ "torch.Tensor.addmm_") | [Contracts away dims](#contracts-away-dims-doc) |
| [`Tensor.addmv()`](tensors.html#torch.Tensor.addmv "torch.Tensor.addmv") ， [`torch.addmv()`](torch.html#torch.addmv "torch.addmv") | [Contracts away dims](#contracts-away-dims-doc) |
| [`Tensor.addmv_()`](tensors.html#torch.Tensor.addmv_ "torch.Tensor.addmv_") | [Contracts away dims](#contracts-away-dims-doc) |
| [`Tensor.align_as()`](named_tensor.html#torch.Tensor.align_as "torch.Tensor.align_as") | 查看文件 |
| [`Tensor.align_to()`](named_tensor.html#torch.Tensor.align_to "torch.Tensor.align_to") | See documentation |
| `Tensor.all()`，`torch.all()` | 没有 |
| `Tensor.any()`，`torch.any()` | None |
| [`Tensor.asin()`](tensors.html#torch.Tensor.asin "torch.Tensor.asin") ， [`torch.asin()`](torch.html#torch.asin "torch.asin") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.asin_()`](tensors.html#torch.Tensor.asin_ "torch.Tensor.asin_") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.atan()`](tensors.html#torch.Tensor.atan "torch.Tensor.atan") ， [`torch.atan()`](torch.html#torch.atan "torch.atan") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.atan2()`](tensors.html#torch.Tensor.atan2 "torch.Tensor.atan2") ， [`torch.atan2()`](torch.html#torch.atan2 "torch.atan2") | [Unifies names from inputs](#unifies-names-from-inputs-doc) |
| [`Tensor.atan2_()`](tensors.html#torch.Tensor.atan2_ "torch.Tensor.atan2_") | [Unifies names from inputs](#unifies-names-from-inputs-doc) |
| [`Tensor.atan_()`](tensors.html#torch.Tensor.atan_ "torch.Tensor.atan_") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.bernoulli()`](tensors.html#torch.Tensor.bernoulli "torch.Tensor.bernoulli") ， [`torch.bernoulli()`](torch.html#torch.bernoulli "torch.bernoulli") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.bernoulli_()`](tensors.html#torch.Tensor.bernoulli_ "torch.Tensor.bernoulli_") | None |
| [`Tensor.bfloat16()`](tensors.html#torch.Tensor.bfloat16 "torch.Tensor.bfloat16") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.bitwise_not()`](tensors.html#torch.Tensor.bitwise_not "torch.Tensor.bitwise_not") ， [`torch.bitwise_not()`](torch.html#torch.bitwise_not "torch.bitwise_not") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.bitwise_not_()`](tensors.html#torch.Tensor.bitwise_not_ "torch.Tensor.bitwise_not_") | None |
| [`Tensor.bmm()`](tensors.html#torch.Tensor.bmm "torch.Tensor.bmm") ， [`torch.bmm()`](torch.html#torch.bmm "torch.bmm") | [Contracts away dims](#contracts-away-dims-doc) |
| [`Tensor.bool()`](tensors.html#torch.Tensor.bool "torch.Tensor.bool") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.byte()`](tensors.html#torch.Tensor.byte "torch.Tensor.byte") | [Keeps input names](#keeps-input-names-doc) |
| [`torch.cat()`](torch.html#torch.cat "torch.cat") | [Unifies names from inputs](#unifies-names-from-inputs-doc) |
| [`Tensor.cauchy_()`](tensors.html#torch.Tensor.cauchy_ "torch.Tensor.cauchy_") | None |
| [`Tensor.ceil()`](tensors.html#torch.Tensor.ceil "torch.Tensor.ceil") ， [`torch.ceil()`](torch.html#torch.ceil "torch.ceil") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.ceil_()`](tensors.html#torch.Tensor.ceil_ "torch.Tensor.ceil_") | None |
| [`Tensor.char()`](tensors.html#torch.Tensor.char "torch.Tensor.char") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.chunk()`](tensors.html#torch.Tensor.chunk "torch.Tensor.chunk") ， [`torch.chunk()`](torch.html#torch.chunk "torch.chunk") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.clamp()`](tensors.html#torch.Tensor.clamp "torch.Tensor.clamp") ， [`torch.clamp()`](torch.html#torch.clamp "torch.clamp") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.clamp_()`](tensors.html#torch.Tensor.clamp_ "torch.Tensor.clamp_") | None |
| [`Tensor.copy_()`](tensors.html#torch.Tensor.copy_ "torch.Tensor.copy_") | [输出功能和就地变体](#out-function-semantics-doc) |
| [`Tensor.cos()`](tensors.html#torch.Tensor.cos "torch.Tensor.cos") ， [`torch.cos()`](torch.html#torch.cos "torch.cos") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.cos_()`](tensors.html#torch.Tensor.cos_ "torch.Tensor.cos_") | None |
| [`Tensor.cosh()`](tensors.html#torch.Tensor.cosh "torch.Tensor.cosh") ， [`torch.cosh()`](torch.html#torch.cosh "torch.cosh") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.cosh_()`](tensors.html#torch.Tensor.cosh_ "torch.Tensor.cosh_") | None |
| [`Tensor.cpu()`](tensors.html#torch.Tensor.cpu "torch.Tensor.cpu") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.cuda()`](tensors.html#torch.Tensor.cuda "torch.Tensor.cuda") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.cumprod()`](tensors.html#torch.Tensor.cumprod "torch.Tensor.cumprod") ， [`torch.cumprod()`](torch.html#torch.cumprod "torch.cumprod") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.cumsum()`](tensors.html#torch.Tensor.cumsum "torch.Tensor.cumsum") ， [`torch.cumsum()`](torch.html#torch.cumsum "torch.cumsum") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.data_ptr()`](tensors.html#torch.Tensor.data_ptr "torch.Tensor.data_ptr") | None |
| [`Tensor.detach()`](autograd.html#torch.Tensor.detach "torch.Tensor.detach") ，`torch.detach()` | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.detach_()`](autograd.html#torch.Tensor.detach_ "torch.Tensor.detach_") | None |
| [`Tensor.device`](tensors.html#torch.Tensor.device "torch.Tensor.device") ， [`torch.device()`](tensor_attributes.html#torch.torch.device "torch.torch.device") | None |
| [`Tensor.digamma()`](tensors.html#torch.Tensor.digamma "torch.Tensor.digamma") ， [`torch.digamma()`](torch.html#torch.digamma "torch.digamma") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.digamma_()`](tensors.html#torch.Tensor.digamma_ "torch.Tensor.digamma_") | None |
| [`Tensor.dim()`](tensors.html#torch.Tensor.dim "torch.Tensor.dim") | None |
| [`Tensor.div()`](tensors.html#torch.Tensor.div "torch.Tensor.div") ， [`torch.div()`](torch.html#torch.div "torch.div") | [Unifies names from inputs](#unifies-names-from-inputs-doc) |
| [`Tensor.div_()`](tensors.html#torch.Tensor.div_ "torch.Tensor.div_") | [Unifies names from inputs](#unifies-names-from-inputs-doc) |
| [`Tensor.dot()`](tensors.html#torch.Tensor.dot "torch.Tensor.dot") ， [`torch.dot()`](torch.html#torch.dot "torch.dot") | None |
| [`Tensor.double()`](tensors.html#torch.Tensor.double "torch.Tensor.double") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.element_size()`](tensors.html#torch.Tensor.element_size "torch.Tensor.element_size") | None |
| [`torch.empty()`](torch.html#torch.empty "torch.empty") | [工厂功能](#factory-doc) |
| [`torch.empty_like()`](torch.html#torch.empty_like "torch.empty_like") | [Factory functions](#factory-doc) |
| [`Tensor.eq()`](tensors.html#torch.Tensor.eq "torch.Tensor.eq") ， [`torch.eq()`](torch.html#torch.eq "torch.eq") | [Unifies names from inputs](#unifies-names-from-inputs-doc) |
| [`Tensor.erf()`](tensors.html#torch.Tensor.erf "torch.Tensor.erf") ， [`torch.erf()`](torch.html#torch.erf "torch.erf") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.erf_()`](tensors.html#torch.Tensor.erf_ "torch.Tensor.erf_") | None |
| [`Tensor.erfc()`](tensors.html#torch.Tensor.erfc "torch.Tensor.erfc") ， [`torch.erfc()`](torch.html#torch.erfc "torch.erfc") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.erfc_()`](tensors.html#torch.Tensor.erfc_ "torch.Tensor.erfc_") | None |
| [`Tensor.erfinv()`](tensors.html#torch.Tensor.erfinv "torch.Tensor.erfinv") ， [`torch.erfinv()`](torch.html#torch.erfinv "torch.erfinv") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.erfinv_()`](tensors.html#torch.Tensor.erfinv_ "torch.Tensor.erfinv_") | None |
| [`Tensor.exp()`](tensors.html#torch.Tensor.exp "torch.Tensor.exp") ， [`torch.exp()`](torch.html#torch.exp "torch.exp") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.exp_()`](tensors.html#torch.Tensor.exp_ "torch.Tensor.exp_") | None |
| [`Tensor.expand()`](tensors.html#torch.Tensor.expand "torch.Tensor.expand") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.expm1()`](tensors.html#torch.Tensor.expm1 "torch.Tensor.expm1") ， [`torch.expm1()`](torch.html#torch.expm1 "torch.expm1") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.expm1_()`](tensors.html#torch.Tensor.expm1_ "torch.Tensor.expm1_") | None |
| [`Tensor.exponential_()`](tensors.html#torch.Tensor.exponential_ "torch.Tensor.exponential_") | None |
| [`Tensor.fill_()`](tensors.html#torch.Tensor.fill_ "torch.Tensor.fill_") | None |
| [`Tensor.flatten()`](tensors.html#torch.Tensor.flatten "torch.Tensor.flatten") ， [`torch.flatten()`](torch.html#torch.flatten "torch.flatten") | See documentation |
| [`Tensor.float()`](tensors.html#torch.Tensor.float "torch.Tensor.float") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.floor()`](tensors.html#torch.Tensor.floor "torch.Tensor.floor") ， [`torch.floor()`](torch.html#torch.floor "torch.floor") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.floor_()`](tensors.html#torch.Tensor.floor_ "torch.Tensor.floor_") | None |
| [`Tensor.frac()`](tensors.html#torch.Tensor.frac "torch.Tensor.frac") ， [`torch.frac()`](torch.html#torch.frac "torch.frac") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.frac_()`](tensors.html#torch.Tensor.frac_ "torch.Tensor.frac_") | None |
| [`Tensor.ge()`](tensors.html#torch.Tensor.ge "torch.Tensor.ge") ， [`torch.ge()`](torch.html#torch.ge "torch.ge") | [Unifies names from inputs](#unifies-names-from-inputs-doc) |
| [`Tensor.get_device()`](tensors.html#torch.Tensor.get_device "torch.Tensor.get_device") ，`torch.get_device()` | None |
| [`Tensor.grad`](autograd.html#torch.Tensor.grad "torch.Tensor.grad") | None |
| [`Tensor.gt()`](tensors.html#torch.Tensor.gt "torch.Tensor.gt") ， [`torch.gt()`](torch.html#torch.gt "torch.gt") | [Unifies names from inputs](#unifies-names-from-inputs-doc) |
| [`Tensor.half()`](tensors.html#torch.Tensor.half "torch.Tensor.half") | [Keeps input names](#keeps-input-names-doc) |
| `Tensor.has_names()` | See documentation |
| [`Tensor.index_fill()`](tensors.html#torch.Tensor.index_fill "torch.Tensor.index_fill") ，`torch.index_fill()` | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.index_fill_()`](tensors.html#torch.Tensor.index_fill_ "torch.Tensor.index_fill_") | None |
| [`Tensor.int()`](tensors.html#torch.Tensor.int "torch.Tensor.int") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.is_contiguous()`](tensors.html#torch.Tensor.is_contiguous "torch.Tensor.is_contiguous") | None |
| [`Tensor.is_cuda`](tensors.html#torch.Tensor.is_cuda "torch.Tensor.is_cuda") | None |
| [`Tensor.is_floating_point()`](tensors.html#torch.Tensor.is_floating_point "torch.Tensor.is_floating_point") ， [`torch.is_floating_point()`](torch.html#torch.is_floating_point "torch.is_floating_point") | None |
| [`Tensor.is_leaf`](autograd.html#torch.Tensor.is_leaf "torch.Tensor.is_leaf") | None |
| [`Tensor.is_pinned()`](tensors.html#torch.Tensor.is_pinned "torch.Tensor.is_pinned") | None |
| [`Tensor.is_shared()`](tensors.html#torch.Tensor.is_shared "torch.Tensor.is_shared") | None |
| [`Tensor.is_signed()`](tensors.html#torch.Tensor.is_signed "torch.Tensor.is_signed") ，`torch.is_signed()` | None |
| [`Tensor.is_sparse`](tensors.html#torch.Tensor.is_sparse "torch.Tensor.is_sparse") | None |
| [`torch.is_tensor()`](torch.html#torch.is_tensor "torch.is_tensor") | None |
| [`Tensor.item()`](tensors.html#torch.Tensor.item "torch.Tensor.item") | None |
| [`Tensor.kthvalue()`](tensors.html#torch.Tensor.kthvalue "torch.Tensor.kthvalue") ， [`torch.kthvalue()`](torch.html#torch.kthvalue "torch.kthvalue") | [移除尺寸](#removes-dimensions-doc) |
| [`Tensor.le()`](tensors.html#torch.Tensor.le "torch.Tensor.le") ， [`torch.le()`](torch.html#torch.le "torch.le") | [Unifies names from inputs](#unifies-names-from-inputs-doc) |
| [`Tensor.log()`](tensors.html#torch.Tensor.log "torch.Tensor.log") ， [`torch.log()`](torch.html#torch.log "torch.log") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.log10()`](tensors.html#torch.Tensor.log10 "torch.Tensor.log10") ， [`torch.log10()`](torch.html#torch.log10 "torch.log10") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.log10_()`](tensors.html#torch.Tensor.log10_ "torch.Tensor.log10_") | None |
| [`Tensor.log1p()`](tensors.html#torch.Tensor.log1p "torch.Tensor.log1p") ， [`torch.log1p()`](torch.html#torch.log1p "torch.log1p") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.log1p_()`](tensors.html#torch.Tensor.log1p_ "torch.Tensor.log1p_") | None |
| [`Tensor.log2()`](tensors.html#torch.Tensor.log2 "torch.Tensor.log2") ， [`torch.log2()`](torch.html#torch.log2 "torch.log2") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.log2_()`](tensors.html#torch.Tensor.log2_ "torch.Tensor.log2_") | None |
| [`Tensor.log_()`](tensors.html#torch.Tensor.log_ "torch.Tensor.log_") | None |
| [`Tensor.log_normal_()`](tensors.html#torch.Tensor.log_normal_ "torch.Tensor.log_normal_") | None |
| [`Tensor.logical_not()`](tensors.html#torch.Tensor.logical_not "torch.Tensor.logical_not") ， [`torch.logical_not()`](torch.html#torch.logical_not "torch.logical_not") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.logical_not_()`](tensors.html#torch.Tensor.logical_not_ "torch.Tensor.logical_not_") | None |
| [`Tensor.logsumexp()`](tensors.html#torch.Tensor.logsumexp "torch.Tensor.logsumexp") ， [`torch.logsumexp()`](torch.html#torch.logsumexp "torch.logsumexp") | [Removes dimensions](#removes-dimensions-doc) |
| [`Tensor.long()`](tensors.html#torch.Tensor.long "torch.Tensor.long") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.lt()`](tensors.html#torch.Tensor.lt "torch.Tensor.lt") ， [`torch.lt()`](torch.html#torch.lt "torch.lt") | [Unifies names from inputs](#unifies-names-from-inputs-doc) |
| [`torch.manual_seed()`](torch.html#torch.manual_seed "torch.manual_seed") | None |
| [`Tensor.masked_fill()`](tensors.html#torch.Tensor.masked_fill "torch.Tensor.masked_fill") ，`torch.masked_fill()` | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.masked_fill_()`](tensors.html#torch.Tensor.masked_fill_ "torch.Tensor.masked_fill_") | None |
| [`Tensor.masked_select()`](tensors.html#torch.Tensor.masked_select "torch.Tensor.masked_select") ， [`torch.masked_select()`](torch.html#torch.masked_select "torch.masked_select") | 将遮罩对齐到输入，然后 unified_names_from_input_tensors |
| [`Tensor.matmul()`](tensors.html#torch.Tensor.matmul "torch.Tensor.matmul") ， [`torch.matmul()`](torch.html#torch.matmul "torch.matmul") | [Contracts away dims](#contracts-away-dims-doc) |
| [`Tensor.mean()`](tensors.html#torch.Tensor.mean "torch.Tensor.mean") ， [`torch.mean()`](torch.html#torch.mean "torch.mean") | [Removes dimensions](#removes-dimensions-doc) |
| [`Tensor.median()`](tensors.html#torch.Tensor.median "torch.Tensor.median") ， [`torch.median()`](torch.html#torch.median "torch.median") | [Removes dimensions](#removes-dimensions-doc) |
| [`Tensor.mm()`](tensors.html#torch.Tensor.mm "torch.Tensor.mm") ， [`torch.mm()`](torch.html#torch.mm "torch.mm") | [Contracts away dims](#contracts-away-dims-doc) |
| [`Tensor.mode()`](tensors.html#torch.Tensor.mode "torch.Tensor.mode") ， [`torch.mode()`](torch.html#torch.mode "torch.mode") | [Removes dimensions](#removes-dimensions-doc) |
| [`Tensor.mul()`](tensors.html#torch.Tensor.mul "torch.Tensor.mul") ， [`torch.mul()`](torch.html#torch.mul "torch.mul") | [Unifies names from inputs](#unifies-names-from-inputs-doc) |
| [`Tensor.mul_()`](tensors.html#torch.Tensor.mul_ "torch.Tensor.mul_") | [Unifies names from inputs](#unifies-names-from-inputs-doc) |
| [`Tensor.mv()`](tensors.html#torch.Tensor.mv "torch.Tensor.mv") ， [`torch.mv()`](torch.html#torch.mv "torch.mv") | [Contracts away dims](#contracts-away-dims-doc) |
| [`Tensor.names`](named_tensor.html#torch.Tensor.names "torch.Tensor.names") | See documentation |
| [`Tensor.narrow()`](tensors.html#torch.Tensor.narrow "torch.Tensor.narrow") ， [`torch.narrow()`](torch.html#torch.narrow "torch.narrow") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.ndim`](tensors.html#torch.Tensor.ndim "torch.Tensor.ndim") | None |
| [`Tensor.ndimension()`](tensors.html#torch.Tensor.ndimension "torch.Tensor.ndimension") | None |
| [`Tensor.ne()`](tensors.html#torch.Tensor.ne "torch.Tensor.ne") ， [`torch.ne()`](torch.html#torch.ne "torch.ne") | [Unifies names from inputs](#unifies-names-from-inputs-doc) |
| [`Tensor.neg()`](tensors.html#torch.Tensor.neg "torch.Tensor.neg") ， [`torch.neg()`](torch.html#torch.neg "torch.neg") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.neg_()`](tensors.html#torch.Tensor.neg_ "torch.Tensor.neg_") | None |
| [`torch.normal()`](torch.html#torch.normal "torch.normal") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.normal_()`](tensors.html#torch.Tensor.normal_ "torch.Tensor.normal_") | None |
| [`Tensor.numel()`](tensors.html#torch.Tensor.numel "torch.Tensor.numel") ， [`torch.numel()`](torch.html#torch.numel "torch.numel") | None |
| [`torch.ones()`](torch.html#torch.ones "torch.ones") | [Factory functions](#factory-doc) |
| [`Tensor.pow()`](tensors.html#torch.Tensor.pow "torch.Tensor.pow") ， [`torch.pow()`](torch.html#torch.pow "torch.pow") | [Unifies names from inputs](#unifies-names-from-inputs-doc) |
| [`Tensor.pow_()`](tensors.html#torch.Tensor.pow_ "torch.Tensor.pow_") | None |
| [`Tensor.prod()`](tensors.html#torch.Tensor.prod "torch.Tensor.prod") ， [`torch.prod()`](torch.html#torch.prod "torch.prod") | [Removes dimensions](#removes-dimensions-doc) |
| [`torch.rand()`](torch.html#torch.rand "torch.rand") | [Factory functions](#factory-doc) |
| [`torch.rand()`](torch.html#torch.rand "torch.rand") | [Factory functions](#factory-doc) |
| [`torch.randn()`](torch.html#torch.randn "torch.randn") | [Factory functions](#factory-doc) |
| [`torch.randn()`](torch.html#torch.randn "torch.randn") | [Factory functions](#factory-doc) |
| [`Tensor.random_()`](tensors.html#torch.Tensor.random_ "torch.Tensor.random_") | None |
| [`Tensor.reciprocal()`](tensors.html#torch.Tensor.reciprocal "torch.Tensor.reciprocal") ， [`torch.reciprocal()`](torch.html#torch.reciprocal "torch.reciprocal") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.reciprocal_()`](tensors.html#torch.Tensor.reciprocal_ "torch.Tensor.reciprocal_") | None |
| [`Tensor.refine_names()`](named_tensor.html#torch.Tensor.refine_names "torch.Tensor.refine_names") | See documentation |
| [`Tensor.register_hook()`](autograd.html#torch.Tensor.register_hook "torch.Tensor.register_hook") | None |
| [`Tensor.rename()`](named_tensor.html#torch.Tensor.rename "torch.Tensor.rename") | See documentation |
| [`Tensor.rename_()`](named_tensor.html#torch.Tensor.rename_ "torch.Tensor.rename_") | See documentation |
| [`Tensor.requires_grad`](autograd.html#torch.Tensor.requires_grad "torch.Tensor.requires_grad") | None |
| [`Tensor.requires_grad_()`](tensors.html#torch.Tensor.requires_grad_ "torch.Tensor.requires_grad_") | None |
| [`Tensor.resize_()`](tensors.html#torch.Tensor.resize_ "torch.Tensor.resize_") | 只允许不改变形状的调整大小 |
| [`Tensor.resize_as_()`](tensors.html#torch.Tensor.resize_as_ "torch.Tensor.resize_as_") | Only allow resizes that do not change shape |
| [`Tensor.round()`](tensors.html#torch.Tensor.round "torch.Tensor.round") ， [`torch.round()`](torch.html#torch.round "torch.round") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.round_()`](tensors.html#torch.Tensor.round_ "torch.Tensor.round_") | None |
| [`Tensor.rsqrt()`](tensors.html#torch.Tensor.rsqrt "torch.Tensor.rsqrt") ， [`torch.rsqrt()`](torch.html#torch.rsqrt "torch.rsqrt") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.rsqrt_()`](tensors.html#torch.Tensor.rsqrt_ "torch.Tensor.rsqrt_") | None |
| [`Tensor.select()`](tensors.html#torch.Tensor.select "torch.Tensor.select") ，`torch.select()` | [Removes dimensions](#removes-dimensions-doc) |
| [`Tensor.short()`](tensors.html#torch.Tensor.short "torch.Tensor.short") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.sigmoid()`](tensors.html#torch.Tensor.sigmoid "torch.Tensor.sigmoid") ， [`torch.sigmoid()`](torch.html#torch.sigmoid "torch.sigmoid") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.sigmoid_()`](tensors.html#torch.Tensor.sigmoid_ "torch.Tensor.sigmoid_") | None |
| [`Tensor.sign()`](tensors.html#torch.Tensor.sign "torch.Tensor.sign") ， [`torch.sign()`](torch.html#torch.sign "torch.sign") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.sign_()`](tensors.html#torch.Tensor.sign_ "torch.Tensor.sign_") | None |
| [`Tensor.sin()`](tensors.html#torch.Tensor.sin "torch.Tensor.sin") ， [`torch.sin()`](torch.html#torch.sin "torch.sin") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.sin_()`](tensors.html#torch.Tensor.sin_ "torch.Tensor.sin_") | None |
| [`Tensor.sinh()`](tensors.html#torch.Tensor.sinh "torch.Tensor.sinh") ， [`torch.sinh()`](torch.html#torch.sinh "torch.sinh") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.sinh_()`](tensors.html#torch.Tensor.sinh_ "torch.Tensor.sinh_") | None |
| [`Tensor.size()`](tensors.html#torch.Tensor.size "torch.Tensor.size") | None |
| [`Tensor.split()`](tensors.html#torch.Tensor.split "torch.Tensor.split") ， [`torch.split()`](torch.html#torch.split "torch.split") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.sqrt()`](tensors.html#torch.Tensor.sqrt "torch.Tensor.sqrt") ， [`torch.sqrt()`](torch.html#torch.sqrt "torch.sqrt") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.sqrt_()`](tensors.html#torch.Tensor.sqrt_ "torch.Tensor.sqrt_") | None |
| [`Tensor.squeeze()`](tensors.html#torch.Tensor.squeeze "torch.Tensor.squeeze") ， [`torch.squeeze()`](torch.html#torch.squeeze "torch.squeeze") | [Removes dimensions](#removes-dimensions-doc) |
| [`Tensor.std()`](tensors.html#torch.Tensor.std "torch.Tensor.std") ， [`torch.std()`](torch.html#torch.std "torch.std") | [Removes dimensions](#removes-dimensions-doc) |
| [`torch.std_mean()`](torch.html#torch.std_mean "torch.std_mean") | [Removes dimensions](#removes-dimensions-doc) |
| [`Tensor.stride()`](tensors.html#torch.Tensor.stride "torch.Tensor.stride") | None |
| [`Tensor.sub()`](tensors.html#torch.Tensor.sub "torch.Tensor.sub") ，`torch.sub()` | [Unifies names from inputs](#unifies-names-from-inputs-doc) |
| [`Tensor.sub_()`](tensors.html#torch.Tensor.sub_ "torch.Tensor.sub_") | [Unifies names from inputs](#unifies-names-from-inputs-doc) |
| [`Tensor.sum()`](tensors.html#torch.Tensor.sum "torch.Tensor.sum") ， [`torch.sum()`](torch.html#torch.sum "torch.sum") | [Removes dimensions](#removes-dimensions-doc) |
| [`Tensor.tan()`](tensors.html#torch.Tensor.tan "torch.Tensor.tan") ， [`torch.tan()`](torch.html#torch.tan "torch.tan") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.tan_()`](tensors.html#torch.Tensor.tan_ "torch.Tensor.tan_") | None |
| [`Tensor.tanh()`](tensors.html#torch.Tensor.tanh "torch.Tensor.tanh") ， [`torch.tanh()`](torch.html#torch.tanh "torch.tanh") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.tanh_()`](tensors.html#torch.Tensor.tanh_ "torch.Tensor.tanh_") | None |
| [`torch.tensor()`](torch.html#torch.tensor "torch.tensor") | [Factory functions](#factory-doc) |
| [`Tensor.to()`](tensors.html#torch.Tensor.to "torch.Tensor.to") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.topk()`](tensors.html#torch.Tensor.topk "torch.Tensor.topk") ， [`torch.topk()`](torch.html#torch.topk "torch.topk") | [Removes dimensions](#removes-dimensions-doc) |
| [`Tensor.transpose()`](tensors.html#torch.Tensor.transpose "torch.Tensor.transpose") ， [`torch.transpose()`](torch.html#torch.transpose "torch.transpose") | [排列尺寸](#permutes-dimensions-doc) |
| [`Tensor.trunc()`](tensors.html#torch.Tensor.trunc "torch.Tensor.trunc") ， [`torch.trunc()`](torch.html#torch.trunc "torch.trunc") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.trunc_()`](tensors.html#torch.Tensor.trunc_ "torch.Tensor.trunc_") | None |
| [`Tensor.type()`](tensors.html#torch.Tensor.type "torch.Tensor.type") | None |
| [`Tensor.type_as()`](tensors.html#torch.Tensor.type_as "torch.Tensor.type_as") | [Keeps input names](#keeps-input-names-doc) |
| [`Tensor.unbind()`](tensors.html#torch.Tensor.unbind "torch.Tensor.unbind") ， [`torch.unbind()`](torch.html#torch.unbind "torch.unbind") | [Removes dimensions](#removes-dimensions-doc) |
| [`Tensor.unflatten()`](named_tensor.html#torch.Tensor.unflatten "torch.Tensor.unflatten") | See documentation |
| [`Tensor.uniform_()`](tensors.html#torch.Tensor.uniform_ "torch.Tensor.uniform_") | None |
| [`Tensor.var()`](tensors.html#torch.Tensor.var "torch.Tensor.var") ， [`torch.var()`](torch.html#torch.var "torch.var") | [Removes dimensions](#removes-dimensions-doc) |
| [`torch.var_mean()`](torch.html#torch.var_mean "torch.var_mean") | [Removes dimensions](#removes-dimensions-doc) |
| [`Tensor.zero_()`](tensors.html#torch.Tensor.zero_ "torch.Tensor.zero_") | None |
| [`torch.zeros()`](torch.html#torch.zeros "torch.zeros") | [Factory functions](#factory-doc) |

## 保留输入名称

所有逐点一元函数以及其他一些一元函数都遵循此规则。

*   检查姓名：无

*   传播名称：输入张量的名称会传播到输出。

```
>>> x = torch.randn(3, 3, names=('N', 'C'))
>>> x.abs().names
('N', 'C')

```

## 移除尺寸

所有缩小操作，例如 [`sum()`](tensors.html#torch.Tensor.sum "torch.Tensor.sum") ，都会通过缩小所需尺寸来删除尺寸。 [`select()`](tensors.html#torch.Tensor.select "torch.Tensor.select") 和 [`squeeze()`](tensors.html#torch.Tensor.squeeze "torch.Tensor.squeeze") 等其他操作会删除尺寸。

只要有人可以将整数维度索引传递给运算符，就可以传递维度名称。 包含维索引列表的函数也可以包含维名称列表。

*   检查名称：如果`dim`或`dims`作为名称列表传入，请检查`self`中是否存在这些名称。

*   传播名称：如果在输出张量中不存在`dim`或`dims`指定的输入张量的尺寸，则这些尺寸的相应名称不会出现在`output.names`中。

```
>>> x = torch.randn(1, 3, 3, 3, names=('N', 'C', 'H', 'W'))
>>> x.squeeze('N').names
('C', 'H', 'W')

>>> x = torch.randn(3, 3, 3, 3, names=('N', 'C', 'H', 'W'))
>>> x.sum(['N', 'C']).names
('H', 'W')

# Reduction ops with keepdim=True don't actually remove dimensions.
>>> x = torch.randn(3, 3, 3, 3, names=('N', 'C', 'H', 'W'))
>>> x.sum(['N', 'C'], keepdim=True).names
('N', 'C', 'H', 'W')

```

## 统一输入中的名称

所有二进制算术运算都遵循此规则。 广播操作仍然从右侧进行位置广播，以保持与未命名张量的兼容性。 要通过名称执行显式广播，请使用 [`Tensor.align_as()`](named_tensor.html#torch.Tensor.align_as "torch.Tensor.align_as") 。

*   检查名称：所有名称都必须从右侧位置匹配。 即，在`tensor + other`中，对于`(-min(tensor.dim(), other.dim()) + 1, -1]`中的所有`i`，`match(tensor.names[i], other.names[i])`必须为 true。

*   检查名称：此外，所有命名的尺寸必须从右对齐。 在匹配期间，如果我们将命名尺寸`A`与未命名尺寸`None`匹配，则`A`不得出现在具有未命名尺寸的张量中。

*   传播名称：从两个张量的右边开始统一名称对，以产生输出名称。

例如，

```
# tensor: Tensor[   N, None]
# other:  Tensor[None,    C]
>>> tensor = torch.randn(3, 3, names=('N', None))
>>> other = torch.randn(3, 3, names=(None, 'C'))
>>> (tensor + other).names
('N', 'C')

```

检查姓名：

*   `match(tensor.names[-1], other.names[-1])`是`True`

*   `match(tensor.names[-2], tensor.names[-2])`是`True`

*   由于我们将 [`tensor`](torch.html#torch.tensor "torch.tensor") 中的`None`与`'C'`匹配，因此请确保 [`tensor`](torch.html#torch.tensor "torch.tensor") 中不存在`'C'`。

*   检查以确保`other`中不存在`'N'`(不存在）。

最后，使用`[unify('N', None), unify(None, 'C')] = ['N', 'C']`计算输出名称

更多示例：

```
# Dimensions don't match from the right:
# tensor: Tensor[N, C]
# other:  Tensor[   N]
>>> tensor = torch.randn(3, 3, names=('N', 'C'))
>>> other = torch.randn(3, names=('N',))
>>> (tensor + other).names
RuntimeError: Error when attempting to broadcast dims ['N', 'C'] and dims
['N']: dim 'C' and dim 'N' are at the same position from the right but do
not match.

# Dimensions aren't aligned when matching tensor.names[-1] and other.names[-1]:
# tensor: Tensor[N, None]
# other:  Tensor[      N]
>>> tensor = torch.randn(3, 3, names=('N', None))
>>> other = torch.randn(3, names=('N',))
>>> (tensor + other).names
RuntimeError: Misaligned dims when attempting to broadcast dims ['N'] and
dims ['N', None]: dim 'N' appears in a different position from the right
across both lists.

```

注意

在最后两个示例中，可以通过名称对齐张量，然后执行加法。 使用 [`Tensor.align_as()`](named_tensor.html#torch.Tensor.align_as "torch.Tensor.align_as") 按名称对齐张量，或使用 [`Tensor.align_to()`](named_tensor.html#torch.Tensor.align_to "torch.Tensor.align_to") 将张量对齐到自定义尺寸顺序。

## 排列尺寸

某些操作(例如 [`Tensor.t()`](tensors.html#torch.Tensor.t "torch.Tensor.t"))会置换尺寸顺序。 维度名称附加到各个维度，因此也可以排列。

如果操作员输入位置索引`dim`，它也可以采用尺寸名称作为`dim`。

*   检查名称：如果将`dim`作为名称传递，请检查其是否在张量中存在。

*   传播名称：以与要排列的维相同的方式排列维名称。

```
>>> x = torch.randn(3, 3, names=('N', 'C'))
>>> x.transpose('N', 'C').names
('C', 'N')

```

## 收缩消失

矩阵乘法函数遵循此方法的某些变体。 让我们先通过 [`torch.mm()`](torch.html#torch.mm "torch.mm") ，然后概括一下批矩阵乘法的规则。

对于`torch.mm(tensor, other)`：

*   Check names: None

*   传播名称：结果名称为`(tensor.names[-2], other.names[-1])`。

```
>>> x = torch.randn(3, 3, names=('N', 'D'))
>>> y = torch.randn(3, 3, names=('in', 'out'))
>>> x.mm(y).names
('N', 'out')

```

本质上，矩阵乘法在二维上执行点积运算，使它们折叠。 当两个张量矩阵相乘时，收缩尺寸消失，并且不出现在输出张量中。

[`torch.mv()`](torch.html#torch.mv "torch.mv") ， [`torch.dot()`](torch.html#torch.dot "torch.dot") 的工作方式类似：名称推断不会检查输入名称，并且会删除点积所涉及的尺寸：

```
>>> x = torch.randn(3, 3, names=('N', 'D'))
>>> y = torch.randn(3, names=('something',))
>>> x.mv(y).names
('N',)

```

现在，让我们看一下`torch.matmul(tensor, other)`。 假设`tensor.dim() &gt;= 2`和`other.dim() &gt;= 2`。

*   检查名称：检查输入的批次尺寸是否对齐并可以广播。 请参见[统一输入](#unifies-names-from-inputs-doc)的名称，以了解对齐输入的含义。

*   传播名称：结果名称是通过统一批次尺寸并删除合同规定的尺寸获得的：`unify(tensor.names[:-2], other.names[:-2]) + (tensor.names[-2], other.names[-1])`。

例子：

```
# Batch matrix multiply of matrices Tensor['C', 'D'] and Tensor['E', 'F'].
# 'A', 'B' are batch dimensions.
>>> x = torch.randn(3, 3, 3, 3, names=('A', 'B', 'C', 'D))
>>> y = torch.randn(3, 3, 3, names=('B', 'E', 'F))
>>> torch.matmul(x, y).names
('A', 'B', 'C', 'F')

```

最后，还有许多功能的融合`add`版本。 即 [`addmm()`](torch.html#torch.addmm "torch.addmm") 和 [`addmv()`](torch.html#torch.addmv "torch.addmv") 。 这些被视为构成 [`mm()`](torch.html#torch.mm "torch.mm") 的名称推断和 [`add()`](torch.html#torch.add "torch.add") 的命名推断。

## 工厂功能

现在，工厂函数采用新的`names`参数，该参数将名称与每个维度相关联。

```
>>> torch.zeros(2, 3, names=('N', 'C'))
tensor([[0., 0., 0.],
        [0., 0., 0.]], names=('N', 'C'))

```

## 输出功能和就地变型

指定为`out=`张量的张量具有以下行为：

*   如果没有命名维，则将从操作中计算出的名称传播到其中。

*   如果它具有任何命名维，则从该操作计算出的名称必须与现有名称完全相同。 否则，操作错误。

所有就地方法都会将输入修改为具有与根据名称推断计算出的名称相同的名称。 例如，

```
>>> x = torch.randn(3, 3)
>>> y = torch.randn(3, 3, names=('N', 'C'))
>>> x.names
(None, None)

>>> x += y
>>> x.names
('N', 'C')

```