Rate this Page

torch.Tensor#

Created On: Dec 23, 2016 | Last Updated On: Jun 27, 2025

Atorch.Tensor is a multi-dimensional matrix containing elements ofa single data type. Please seetorch.dtype for more details about dtype support.

Initializing and basic operations#

A tensor can be constructed from a Pythonlist or sequence using thetorch.tensor() constructor:

>>>torch.tensor([[1.,-1.],[1.,-1.]])tensor([[ 1.0000, -1.0000],        [ 1.0000, -1.0000]])>>>torch.tensor(np.array([[1,2,3],[4,5,6]]))tensor([[ 1,  2,  3],        [ 4,  5,  6]])

Warning

torch.tensor() always copiesdata. If you have a Tensordata and just want to change itsrequires_grad flag, userequires_grad_() ordetach() to avoid a copy.If you have a numpy array and want to avoid a copy, usetorch.as_tensor().

A tensor of specific data type can be constructed by passing atorch.dtype and/or atorch.device to aconstructor or tensor creation op:

>>>torch.zeros([2,4],dtype=torch.int32)tensor([[ 0,  0,  0,  0],        [ 0,  0,  0,  0]], dtype=torch.int32)>>>cuda0=torch.device('cuda:0')>>>torch.ones([2,4],dtype=torch.float64,device=cuda0)tensor([[ 1.0000,  1.0000,  1.0000,  1.0000],        [ 1.0000,  1.0000,  1.0000,  1.0000]], dtype=torch.float64, device='cuda:0')

For more information about building Tensors, seeCreation Ops

The contents of a tensor can be accessed and modified using Python’s indexingand slicing notation:

>>>x=torch.tensor([[1,2,3],[4,5,6]])>>>print(x[1][2])tensor(6)>>>x[0][1]=8>>>print(x)tensor([[ 1,  8,  3],        [ 4,  5,  6]])

Usetorch.Tensor.item() to get a Python number from a tensor containing asingle value:

>>>x=torch.tensor([[1]])>>>xtensor([[ 1]])>>>x.item()1>>>x=torch.tensor(2.5)>>>xtensor(2.5000)>>>x.item()2.5

For more information about indexing, seeIndexing, Slicing, Joining, Mutating Ops

A tensor can be created withrequires_grad=True so thattorch.autograd records operations on them for automatic differentiation.

>>>x=torch.tensor([[1.,-1.],[1.,1.]],requires_grad=True)>>>out=x.pow(2).sum()>>>out.backward()>>>x.gradtensor([[ 2.0000, -2.0000],        [ 2.0000,  2.0000]])

Each tensor has an associatedtorch.Storage, which holds its data.The tensor class also provides multi-dimensional,stridedview of a storage and defines numeric operations on it.

Note

For more information on tensor views, seeTensor Views.

Note

For more information on thetorch.dtype,torch.device, andtorch.layout attributes of atorch.Tensor, seeTensor Attributes.

Note

Methods which mutate a tensor are marked with an underscore suffix.For example,torch.FloatTensor.abs_() computes the absolute valuein-place and returns the modified tensor, whiletorch.FloatTensor.abs()computes the result in a new tensor.

Note

To change an existing tensor’storch.device and/ortorch.dtype, consider usingto() method on the tensor.

Warning

Current implementation oftorch.Tensor introduces memory overhead,thus it might lead to unexpectedly high memory usage in the applications with many tiny tensors.If this is your case, consider using one large structure.

Tensor class reference#

classtorch.Tensor#

There are a few main ways to create a tensor, depending on your use case.

  • To create a tensor with pre-existing data, usetorch.tensor().

  • To create a tensor with specific size, usetorch.* tensor creationops (seeCreation Ops).

  • To create a tensor with the same size (and similar types) as another tensor,usetorch.*_like tensor creation ops(seeCreation Ops).

  • To create a tensor with similar type but different size as another tensor,usetensor.new_* creation ops.

  • There is a legacy constructortorch.Tensor whose use is discouraged.Usetorch.tensor() instead.

Tensor.__init__(self,data)#

This constructor is deprecated, we recommend usingtorch.tensor() instead.What this constructor does depends on the type ofdata.

  • Ifdata is a Tensor, returns an alias to the original Tensor. Unliketorch.tensor(), this tracks autograd and will propagate gradients tothe original Tensor.device kwarg is not supported for thisdata type.

  • Ifdata is a sequence or nested sequence, create a tensor of the defaultdtype (typicallytorch.float32) whose data is the values in thesequences, performing coercions if necessary. Notably, this differs fromtorch.tensor() in that this constructor will always construct a floattensor, even if the inputs are all integers.

  • Ifdata is atorch.Size, returns an empty tensor of that size.

This constructor does not support explicitly specifyingdtype ordevice ofthe returned tensor. We recommend usingtorch.tensor() which provides thisfunctionality.

Args:

data (array_like): The tensor to construct from.

Keyword args:
device (torch.device, optional): the desired device of returned tensor.

Default: if None, sametorch.device as this tensor.

Tensor.T#

Returns a view of this tensor with its dimensions reversed.

Ifn is the number of dimensions inx,x.T is equivalent tox.permute(n-1,n-2,...,0).

Warning

The use ofTensor.T() on tensors of dimension other than 2 to reverse their shapeis deprecated and it will throw an error in a future release. ConsidermTto transpose batches of matrices orx.permute(*torch.arange(x.ndim - 1, -1, -1)) to reversethe dimensions of a tensor.

Tensor.H#

Returns a view of a matrix (2-D tensor) conjugated and transposed.

x.H is equivalent tox.transpose(0,1).conj() for complex matrices andx.transpose(0,1) for real matrices.

See also

mH: An attribute that also works on batches of matrices.

Tensor.mT#

Returns a view of this tensor with the last two dimensions transposed.

x.mT is equivalent tox.transpose(-2,-1).

Tensor.mH#

Accessing this property is equivalent to callingadjoint().

Tensor.new_tensor

Returns a new Tensor withdata as the tensor data.

Tensor.new_full

Returns a Tensor of sizesize filled withfill_value.

Tensor.new_empty

Returns a Tensor of sizesize filled with uninitialized data.

Tensor.new_ones

Returns a Tensor of sizesize filled with1.

Tensor.new_zeros

Returns a Tensor of sizesize filled with0.

Tensor.is_cuda

IsTrue if the Tensor is stored on the GPU,False otherwise.

Tensor.is_quantized

IsTrue if the Tensor is quantized,False otherwise.

Tensor.is_meta

IsTrue if the Tensor is a meta tensor,False otherwise.

Tensor.device

Is thetorch.device where this Tensor is.

Tensor.grad

This attribute isNone by default and becomes a Tensor the first time a call tobackward() computes gradients forself.

Tensor.ndim

Alias fordim()

Tensor.real

Returns a new tensor containing real values of theself tensor for a complex-valued input tensor.

Tensor.imag

Returns a new tensor containing imaginary values of theself tensor.

Tensor.nbytes

Returns the number of bytes consumed by the "view" of elements of the Tensor if the Tensor does not use sparse storage layout.

Tensor.itemsize

Alias forelement_size()

Tensor.abs

Seetorch.abs()

Tensor.abs_

In-place version ofabs()

Tensor.absolute

Alias forabs()

Tensor.absolute_

In-place version ofabsolute() Alias forabs_()

Tensor.acos

Seetorch.acos()

Tensor.acos_

In-place version ofacos()

Tensor.arccos

Seetorch.arccos()

Tensor.arccos_

In-place version ofarccos()

Tensor.add

Add a scalar or tensor toself tensor.

Tensor.add_

In-place version ofadd()

Tensor.addbmm

Seetorch.addbmm()

Tensor.addbmm_

In-place version ofaddbmm()

Tensor.addcdiv

Seetorch.addcdiv()

Tensor.addcdiv_

In-place version ofaddcdiv()

Tensor.addcmul

Seetorch.addcmul()

Tensor.addcmul_

In-place version ofaddcmul()

Tensor.addmm

Seetorch.addmm()

Tensor.addmm_

In-place version ofaddmm()

Tensor.sspaddmm

Seetorch.sspaddmm()

Tensor.addmv

Seetorch.addmv()

Tensor.addmv_

In-place version ofaddmv()

Tensor.addr

Seetorch.addr()

Tensor.addr_

In-place version ofaddr()

Tensor.adjoint

Alias foradjoint()

Tensor.allclose

Seetorch.allclose()

Tensor.amax

Seetorch.amax()

Tensor.amin

Seetorch.amin()

Tensor.aminmax

Seetorch.aminmax()

Tensor.angle

Seetorch.angle()

Tensor.apply_

Applies the functioncallable to each element in the tensor, replacing each element with the value returned bycallable.

Tensor.argmax

Seetorch.argmax()

Tensor.argmin

Seetorch.argmin()

Tensor.argsort

Seetorch.argsort()

Tensor.argwhere

Seetorch.argwhere()

Tensor.asin

Seetorch.asin()

Tensor.asin_

In-place version ofasin()

Tensor.arcsin

Seetorch.arcsin()

Tensor.arcsin_

In-place version ofarcsin()

Tensor.as_strided

Seetorch.as_strided()

Tensor.atan

Seetorch.atan()

Tensor.atan_

In-place version ofatan()

Tensor.arctan

Seetorch.arctan()

Tensor.arctan_

In-place version ofarctan()

Tensor.atan2

Seetorch.atan2()

Tensor.atan2_

In-place version ofatan2()

Tensor.arctan2

Seetorch.arctan2()

Tensor.arctan2_

atan2_(other) -> Tensor

Tensor.all

Seetorch.all()

Tensor.any

Seetorch.any()

Tensor.backward

Computes the gradient of current tensor wrt graph leaves.

Tensor.baddbmm

Seetorch.baddbmm()

Tensor.baddbmm_

In-place version ofbaddbmm()

Tensor.bernoulli

Returns a result tensor where eachresult[i]\texttt{result[i]} is independently sampled fromBernoulli(self[i])\text{Bernoulli}(\texttt{self[i]}).

Tensor.bernoulli_

Fills each location ofself with an independent sample fromBernoulli(p)\text{Bernoulli}(\texttt{p}).

Tensor.bfloat16

self.bfloat16() is equivalent toself.to(torch.bfloat16).

Tensor.bincount

Seetorch.bincount()

Tensor.bitwise_not

Seetorch.bitwise_not()

Tensor.bitwise_not_

In-place version ofbitwise_not()

Tensor.bitwise_and

Seetorch.bitwise_and()

Tensor.bitwise_and_

In-place version ofbitwise_and()

Tensor.bitwise_or

Seetorch.bitwise_or()

Tensor.bitwise_or_

In-place version ofbitwise_or()

Tensor.bitwise_xor

Seetorch.bitwise_xor()

Tensor.bitwise_xor_

In-place version ofbitwise_xor()

Tensor.bitwise_left_shift

Seetorch.bitwise_left_shift()

Tensor.bitwise_left_shift_

In-place version ofbitwise_left_shift()

Tensor.bitwise_right_shift

Seetorch.bitwise_right_shift()

Tensor.bitwise_right_shift_

In-place version ofbitwise_right_shift()

Tensor.bmm

Seetorch.bmm()

Tensor.bool

self.bool() is equivalent toself.to(torch.bool).

Tensor.byte

self.byte() is equivalent toself.to(torch.uint8).

Tensor.broadcast_to

Seetorch.broadcast_to().

Tensor.cauchy_

Fills the tensor with numbers drawn from the Cauchy distribution:

Tensor.ceil

Seetorch.ceil()

Tensor.ceil_

In-place version ofceil()

Tensor.char

self.char() is equivalent toself.to(torch.int8).

Tensor.cholesky

Seetorch.cholesky()

Tensor.cholesky_inverse

Seetorch.cholesky_inverse()

Tensor.cholesky_solve

Seetorch.cholesky_solve()

Tensor.chunk

Seetorch.chunk()

Tensor.clamp

Seetorch.clamp()

Tensor.clamp_

In-place version ofclamp()

Tensor.clip

Alias forclamp().

Tensor.clip_

Alias forclamp_().

Tensor.clone

Seetorch.clone()

Tensor.contiguous

Returns a contiguous in memory tensor containing the same data asself tensor.

Tensor.copy_

Copies the elements fromsrc intoself tensor and returnsself.

Tensor.conj

Seetorch.conj()

Tensor.conj_physical

Seetorch.conj_physical()

Tensor.conj_physical_

In-place version ofconj_physical()

Tensor.resolve_conj

Seetorch.resolve_conj()

Tensor.resolve_neg

Seetorch.resolve_neg()

Tensor.copysign

Seetorch.copysign()

Tensor.copysign_

In-place version ofcopysign()

Tensor.cos

Seetorch.cos()

Tensor.cos_

In-place version ofcos()

Tensor.cosh

Seetorch.cosh()

Tensor.cosh_

In-place version ofcosh()

Tensor.corrcoef

Seetorch.corrcoef()

Tensor.count_nonzero

Seetorch.count_nonzero()

Tensor.cov

Seetorch.cov()

Tensor.acosh

Seetorch.acosh()

Tensor.acosh_

In-place version ofacosh()

Tensor.arccosh

acosh() -> Tensor

Tensor.arccosh_

acosh_() -> Tensor

Tensor.cpu

Returns a copy of this object in CPU memory.

Tensor.cross

Seetorch.cross()

Tensor.cuda

Returns a copy of this object in CUDA memory.

Tensor.logcumsumexp

Seetorch.logcumsumexp()

Tensor.cummax

Seetorch.cummax()

Tensor.cummin

Seetorch.cummin()

Tensor.cumprod

Seetorch.cumprod()

Tensor.cumprod_

In-place version ofcumprod()

Tensor.cumsum

Seetorch.cumsum()

Tensor.cumsum_

In-place version ofcumsum()

Tensor.chalf

self.chalf() is equivalent toself.to(torch.complex32).

Tensor.cfloat

self.cfloat() is equivalent toself.to(torch.complex64).

Tensor.cdouble

self.cdouble() is equivalent toself.to(torch.complex128).

Tensor.data_ptr

Returns the address of the first element ofself tensor.

Tensor.deg2rad

Seetorch.deg2rad()

Tensor.dequantize

Given a quantized Tensor, dequantize it and return the dequantized float Tensor.

Tensor.det

Seetorch.det()

Tensor.dense_dim

Return the number of dense dimensions in asparse tensorself.

Tensor.detach

Returns a new Tensor, detached from the current graph.

Tensor.detach_

Detaches the Tensor from the graph that created it, making it a leaf.

Tensor.diag

Seetorch.diag()

Tensor.diag_embed

Seetorch.diag_embed()

Tensor.diagflat

Seetorch.diagflat()

Tensor.diagonal

Seetorch.diagonal()

Tensor.diagonal_scatter

Seetorch.diagonal_scatter()

Tensor.fill_diagonal_

Fill the main diagonal of a tensor that has at least 2-dimensions.

Tensor.fmax

Seetorch.fmax()

Tensor.fmin

Seetorch.fmin()

Tensor.diff

Seetorch.diff()

Tensor.digamma

Seetorch.digamma()

Tensor.digamma_

In-place version ofdigamma()

Tensor.dim

Returns the number of dimensions ofself tensor.

Tensor.dim_order

Returns the uniquely determined tuple of int describing the dim order or physical layout ofself.

Tensor.dist

Seetorch.dist()

Tensor.div

Seetorch.div()

Tensor.div_

In-place version ofdiv()

Tensor.divide

Seetorch.divide()

Tensor.divide_

In-place version ofdivide()

Tensor.dot

Seetorch.dot()

Tensor.double

self.double() is equivalent toself.to(torch.float64).

Tensor.dsplit

Seetorch.dsplit()

Tensor.element_size

Returns the size in bytes of an individual element.

Tensor.eq

Seetorch.eq()

Tensor.eq_

In-place version ofeq()

Tensor.equal

Seetorch.equal()

Tensor.erf

Seetorch.erf()

Tensor.erf_

In-place version oferf()

Tensor.erfc

Seetorch.erfc()

Tensor.erfc_

In-place version oferfc()

Tensor.erfinv

Seetorch.erfinv()

Tensor.erfinv_

In-place version oferfinv()

Tensor.exp

Seetorch.exp()

Tensor.exp_

In-place version ofexp()

Tensor.expm1

Seetorch.expm1()

Tensor.expm1_

In-place version ofexpm1()

Tensor.expand

Returns a new view of theself tensor with singleton dimensions expanded to a larger size.

Tensor.expand_as

Expand this tensor to the same size asother.

Tensor.exponential_

Fillsself tensor with elements drawn from the PDF (probability density function):

Tensor.fix

Seetorch.fix().

Tensor.fix_

In-place version offix()

Tensor.fill_

Fillsself tensor with the specified value.

Tensor.flatten

Seetorch.flatten()

Tensor.flip

Seetorch.flip()

Tensor.fliplr

Seetorch.fliplr()

Tensor.flipud

Seetorch.flipud()

Tensor.float

self.float() is equivalent toself.to(torch.float32).

Tensor.float_power

Seetorch.float_power()

Tensor.float_power_

In-place version offloat_power()

Tensor.floor

Seetorch.floor()

Tensor.floor_

In-place version offloor()

Tensor.floor_divide

Seetorch.floor_divide()

Tensor.floor_divide_

In-place version offloor_divide()

Tensor.fmod

Seetorch.fmod()

Tensor.fmod_

In-place version offmod()

Tensor.frac

Seetorch.frac()

Tensor.frac_

In-place version offrac()

Tensor.frexp

Seetorch.frexp()

Tensor.gather

Seetorch.gather()

Tensor.gcd

Seetorch.gcd()

Tensor.gcd_

In-place version ofgcd()

Tensor.ge

Seetorch.ge().

Tensor.ge_

In-place version ofge().

Tensor.greater_equal

Seetorch.greater_equal().

Tensor.greater_equal_

In-place version ofgreater_equal().

Tensor.geometric_

Fillsself tensor with elements drawn from the geometric distribution:

Tensor.geqrf

Seetorch.geqrf()

Tensor.ger

Seetorch.ger()

Tensor.get_device

For CUDA tensors, this function returns the device ordinal of the GPU on which the tensor resides.

Tensor.gt

Seetorch.gt().

Tensor.gt_

In-place version ofgt().

Tensor.greater

Seetorch.greater().

Tensor.greater_

In-place version ofgreater().

Tensor.half

self.half() is equivalent toself.to(torch.float16).

Tensor.hardshrink

Seetorch.nn.functional.hardshrink()

Tensor.heaviside

Seetorch.heaviside()

Tensor.histc

Seetorch.histc()

Tensor.histogram

Seetorch.histogram()

Tensor.hsplit

Seetorch.hsplit()

Tensor.hypot

Seetorch.hypot()

Tensor.hypot_

In-place version ofhypot()

Tensor.i0

Seetorch.i0()

Tensor.i0_

In-place version ofi0()

Tensor.igamma

Seetorch.igamma()

Tensor.igamma_

In-place version ofigamma()

Tensor.igammac

Seetorch.igammac()

Tensor.igammac_

In-place version ofigammac()

Tensor.index_add_

Accumulate the elements ofalpha timessource into theself tensor by adding to the indices in the order given inindex.

Tensor.index_add

Out-of-place version oftorch.Tensor.index_add_().

Tensor.index_copy_

Copies the elements oftensor into theself tensor by selecting the indices in the order given inindex.

Tensor.index_copy

Out-of-place version oftorch.Tensor.index_copy_().

Tensor.index_fill_

Fills the elements of theself tensor with valuevalue by selecting the indices in the order given inindex.

Tensor.index_fill

Out-of-place version oftorch.Tensor.index_fill_().

Tensor.index_put_

Puts values from the tensorvalues into the tensorself using the indices specified inindices (which is a tuple of Tensors).

Tensor.index_put

Out-place version ofindex_put_().

Tensor.index_reduce_

Accumulate the elements ofsource into theself tensor by accumulating to the indices in the order given inindex using the reduction given by thereduce argument.

Tensor.index_reduce

Tensor.index_select

Seetorch.index_select()

Tensor.indices

Return the indices tensor of asparse COO tensor.

Tensor.inner

Seetorch.inner().

Tensor.int

self.int() is equivalent toself.to(torch.int32).

Tensor.int_repr

Given a quantized Tensor,self.int_repr() returns a CPU Tensor with uint8_t as data type that stores the underlying uint8_t values of the given Tensor.

Tensor.inverse

Seetorch.inverse()

Tensor.isclose

Seetorch.isclose()

Tensor.isfinite

Seetorch.isfinite()

Tensor.isinf

Seetorch.isinf()

Tensor.isposinf

Seetorch.isposinf()

Tensor.isneginf

Seetorch.isneginf()

Tensor.isnan

Seetorch.isnan()

Tensor.is_contiguous

Returns True ifself tensor is contiguous in memory in the order specified by memory format.

Tensor.is_complex

Returns True if the data type ofself is a complex data type.

Tensor.is_conj

Returns True if the conjugate bit ofself is set to true.

Tensor.is_floating_point

Returns True if the data type ofself is a floating point data type.

Tensor.is_inference

Seetorch.is_inference()

Tensor.is_leaf

All Tensors that haverequires_grad which isFalse will be leaf Tensors by convention.

Tensor.is_pinned

Returns true if this tensor resides in pinned memory.

Tensor.is_set_to

Returns True if both tensors are pointing to the exact same memory (same storage, offset, size and stride).

Tensor.is_shared

Checks if tensor is in shared memory.

Tensor.is_signed

Returns True if the data type ofself is a signed data type.

Tensor.is_sparse

IsTrue if the Tensor uses sparse COO storage layout,False otherwise.

Tensor.istft

Seetorch.istft()

Tensor.isreal

Seetorch.isreal()

Tensor.item

Returns the value of this tensor as a standard Python number.

Tensor.kthvalue

Seetorch.kthvalue()

Tensor.lcm

Seetorch.lcm()

Tensor.lcm_

In-place version oflcm()

Tensor.ldexp

Seetorch.ldexp()

Tensor.ldexp_

In-place version ofldexp()

Tensor.le

Seetorch.le().

Tensor.le_

In-place version ofle().

Tensor.less_equal

Seetorch.less_equal().

Tensor.less_equal_

In-place version ofless_equal().

Tensor.lerp

Seetorch.lerp()

Tensor.lerp_

In-place version oflerp()

Tensor.lgamma

Seetorch.lgamma()

Tensor.lgamma_

In-place version oflgamma()

Tensor.log

Seetorch.log()

Tensor.log_

In-place version oflog()

Tensor.logdet

Seetorch.logdet()

Tensor.log10

Seetorch.log10()

Tensor.log10_

In-place version oflog10()

Tensor.log1p

Seetorch.log1p()

Tensor.log1p_

In-place version oflog1p()

Tensor.log2

Seetorch.log2()

Tensor.log2_

In-place version oflog2()

Tensor.log_normal_

Fillsself tensor with numbers samples from the log-normal distribution parameterized by the given meanμ\mu and standard deviationσ\sigma.

Tensor.logaddexp

Seetorch.logaddexp()

Tensor.logaddexp2

Seetorch.logaddexp2()

Tensor.logsumexp

Seetorch.logsumexp()

Tensor.logical_and

Seetorch.logical_and()

Tensor.logical_and_

In-place version oflogical_and()

Tensor.logical_not

Seetorch.logical_not()

Tensor.logical_not_

In-place version oflogical_not()

Tensor.logical_or

Seetorch.logical_or()

Tensor.logical_or_

In-place version oflogical_or()

Tensor.logical_xor

Seetorch.logical_xor()

Tensor.logical_xor_

In-place version oflogical_xor()

Tensor.logit

Seetorch.logit()

Tensor.logit_

In-place version oflogit()

Tensor.long

self.long() is equivalent toself.to(torch.int64).

Tensor.lt

Seetorch.lt().

Tensor.lt_

In-place version oflt().

Tensor.less

lt(other) -> Tensor

Tensor.less_

In-place version ofless().

Tensor.lu

Seetorch.lu()

Tensor.lu_solve

Seetorch.lu_solve()

Tensor.as_subclass

Makes acls instance with the same data pointer asself.

Tensor.map_

Appliescallable for each element inself tensor and the giventensor and stores the results inself tensor.

Tensor.masked_scatter_

Copies elements fromsource intoself tensor at positions where themask is True.

Tensor.masked_scatter

Out-of-place version oftorch.Tensor.masked_scatter_()

Tensor.masked_fill_

Fills elements ofself tensor withvalue wheremask is True.

Tensor.masked_fill

Out-of-place version oftorch.Tensor.masked_fill_()

Tensor.masked_select

Seetorch.masked_select()

Tensor.matmul

Seetorch.matmul()

Tensor.matrix_power

Note

matrix_power() is deprecated, usetorch.linalg.matrix_power() instead.

Tensor.matrix_exp

Seetorch.matrix_exp()

Tensor.max

Seetorch.max()

Tensor.maximum

Seetorch.maximum()

Tensor.mean

Seetorch.mean()

Tensor.module_load

Defines how to transformother when loading it intoself inload_state_dict().

Tensor.nanmean

Seetorch.nanmean()

Tensor.median

Seetorch.median()

Tensor.nanmedian

Seetorch.nanmedian()

Tensor.min

Seetorch.min()

Tensor.minimum

Seetorch.minimum()

Tensor.mm

Seetorch.mm()

Tensor.smm

Seetorch.smm()

Tensor.mode

Seetorch.mode()

Tensor.movedim

Seetorch.movedim()

Tensor.moveaxis

Seetorch.moveaxis()

Tensor.msort

Seetorch.msort()

Tensor.mul

Seetorch.mul().

Tensor.mul_

In-place version ofmul().

Tensor.multiply

Seetorch.multiply().

Tensor.multiply_

In-place version ofmultiply().

Tensor.multinomial

Seetorch.multinomial()

Tensor.mv

Seetorch.mv()

Tensor.mvlgamma

Seetorch.mvlgamma()

Tensor.mvlgamma_

In-place version ofmvlgamma()

Tensor.nansum

Seetorch.nansum()

Tensor.narrow

Seetorch.narrow().

Tensor.narrow_copy

Seetorch.narrow_copy().

Tensor.ndimension

Alias fordim()

Tensor.nan_to_num

Seetorch.nan_to_num().

Tensor.nan_to_num_

In-place version ofnan_to_num().

Tensor.ne

Seetorch.ne().

Tensor.ne_

In-place version ofne().

Tensor.not_equal

Seetorch.not_equal().

Tensor.not_equal_

In-place version ofnot_equal().

Tensor.neg

Seetorch.neg()

Tensor.neg_

In-place version ofneg()

Tensor.negative

Seetorch.negative()

Tensor.negative_

In-place version ofnegative()

Tensor.nelement

Alias fornumel()

Tensor.nextafter

Seetorch.nextafter()

Tensor.nextafter_

In-place version ofnextafter()

Tensor.nonzero

Seetorch.nonzero()

Tensor.norm

Seetorch.norm()

Tensor.normal_

Fillsself tensor with elements samples from the normal distribution parameterized bymean andstd.

Tensor.numel

Seetorch.numel()

Tensor.numpy

Returns the tensor as a NumPyndarray.

Tensor.orgqr

Seetorch.orgqr()

Tensor.ormqr

Seetorch.ormqr()

Tensor.outer

Seetorch.outer().

Tensor.permute

Seetorch.permute()

Tensor.pin_memory

Copies the tensor to pinned memory, if it's not already pinned.

Tensor.pinverse

Seetorch.pinverse()

Tensor.polygamma

Seetorch.polygamma()

Tensor.polygamma_

In-place version ofpolygamma()

Tensor.positive

Seetorch.positive()

Tensor.pow

Seetorch.pow()

Tensor.pow_

In-place version ofpow()

Tensor.prod

Seetorch.prod()

Tensor.put_

Copies the elements fromsource into the positions specified byindex.

Tensor.qr

Seetorch.qr()

Tensor.qscheme

Returns the quantization scheme of a given QTensor.

Tensor.quantile

Seetorch.quantile()

Tensor.nanquantile

Seetorch.nanquantile()

Tensor.q_scale

Given a Tensor quantized by linear(affine) quantization, returns the scale of the underlying quantizer().

Tensor.q_zero_point

Given a Tensor quantized by linear(affine) quantization, returns the zero_point of the underlying quantizer().

Tensor.q_per_channel_scales

Given a Tensor quantized by linear (affine) per-channel quantization, returns a Tensor of scales of the underlying quantizer.

Tensor.q_per_channel_zero_points

Given a Tensor quantized by linear (affine) per-channel quantization, returns a tensor of zero_points of the underlying quantizer.

Tensor.q_per_channel_axis

Given a Tensor quantized by linear (affine) per-channel quantization, returns the index of dimension on which per-channel quantization is applied.

Tensor.rad2deg

Seetorch.rad2deg()

Tensor.random_

Fillsself tensor with numbers sampled from the discrete uniform distribution over[from,to-1].

Tensor.ravel

seetorch.ravel()

Tensor.reciprocal

Seetorch.reciprocal()

Tensor.reciprocal_

In-place version ofreciprocal()

Tensor.record_stream

Marks the tensor as having been used by this stream.

Tensor.register_hook

Registers a backward hook.

Tensor.register_post_accumulate_grad_hook

Registers a backward hook that runs after grad accumulation.

Tensor.remainder

Seetorch.remainder()

Tensor.remainder_

In-place version ofremainder()

Tensor.renorm

Seetorch.renorm()

Tensor.renorm_

In-place version ofrenorm()

Tensor.repeat

Repeats this tensor along the specified dimensions.

Tensor.repeat_interleave

Seetorch.repeat_interleave().

Tensor.requires_grad

IsTrue if gradients need to be computed for this Tensor,False otherwise.

Tensor.requires_grad_

Change if autograd should record operations on this tensor: sets this tensor'srequires_grad attribute in-place.

Tensor.reshape

Returns a tensor with the same data and number of elements asself but with the specified shape.

Tensor.reshape_as

Returns this tensor as the same shape asother.

Tensor.resize_

Resizesself tensor to the specified size.

Tensor.resize_as_

Resizes theself tensor to be the same size as the specifiedtensor.

Tensor.retain_grad

Enables this Tensor to have theirgrad populated duringbackward().

Tensor.retains_grad

IsTrue if this Tensor is non-leaf and itsgrad is enabled to be populated duringbackward(),False otherwise.

Tensor.roll

Seetorch.roll()

Tensor.rot90

Seetorch.rot90()

Tensor.round

Seetorch.round()

Tensor.round_

In-place version ofround()

Tensor.rsqrt

Seetorch.rsqrt()

Tensor.rsqrt_

In-place version ofrsqrt()

Tensor.scatter

Out-of-place version oftorch.Tensor.scatter_()

Tensor.scatter_

Writes all values from the tensorsrc intoself at the indices specified in theindex tensor.

Tensor.scatter_add_

Adds all values from the tensorsrc intoself at the indices specified in theindex tensor in a similar fashion asscatter_().

Tensor.scatter_add

Out-of-place version oftorch.Tensor.scatter_add_()

Tensor.scatter_reduce_

Reduces all values from thesrc tensor to the indices specified in theindex tensor in theself tensor using the applied reduction defined via thereduce argument ("sum","prod","mean","amax","amin").

Tensor.scatter_reduce

Out-of-place version oftorch.Tensor.scatter_reduce_()

Tensor.select

Seetorch.select()

Tensor.select_scatter

Seetorch.select_scatter()

Tensor.set_

Sets the underlying storage, size, and strides.

Tensor.share_memory_

Moves the underlying storage to shared memory.

Tensor.short

self.short() is equivalent toself.to(torch.int16).

Tensor.sigmoid

Seetorch.sigmoid()

Tensor.sigmoid_

In-place version ofsigmoid()

Tensor.sign

Seetorch.sign()

Tensor.sign_

In-place version ofsign()

Tensor.signbit

Seetorch.signbit()

Tensor.sgn

Seetorch.sgn()

Tensor.sgn_

In-place version ofsgn()

Tensor.sin

Seetorch.sin()

Tensor.sin_

In-place version ofsin()

Tensor.sinc

Seetorch.sinc()

Tensor.sinc_

In-place version ofsinc()

Tensor.sinh

Seetorch.sinh()

Tensor.sinh_

In-place version ofsinh()

Tensor.asinh

Seetorch.asinh()

Tensor.asinh_

In-place version ofasinh()

Tensor.arcsinh

Seetorch.arcsinh()

Tensor.arcsinh_

In-place version ofarcsinh()

Tensor.shape

Returns the size of theself tensor.

Tensor.size

Returns the size of theself tensor.

Tensor.slogdet

Seetorch.slogdet()

Tensor.slice_scatter

Seetorch.slice_scatter()

Tensor.softmax

Alias fortorch.nn.functional.softmax().

Tensor.sort

Seetorch.sort()

Tensor.split

Seetorch.split()

Tensor.sparse_mask

Returns a newsparse tensor with values from a strided tensorself filtered by the indices of the sparse tensormask.

Tensor.sparse_dim

Return the number of sparse dimensions in asparse tensorself.

Tensor.sqrt

Seetorch.sqrt()

Tensor.sqrt_

In-place version ofsqrt()

Tensor.square

Seetorch.square()

Tensor.square_

In-place version ofsquare()

Tensor.squeeze

Seetorch.squeeze()

Tensor.squeeze_

In-place version ofsqueeze()

Tensor.std

Seetorch.std()

Tensor.stft

Seetorch.stft()

Tensor.storage

Returns the underlyingTypedStorage.

Tensor.untyped_storage

Returns the underlyingUntypedStorage.

Tensor.storage_offset

Returnsself tensor's offset in the underlying storage in terms of number of storage elements (not bytes).

Tensor.storage_type

Returns the type of the underlying storage.

Tensor.stride

Returns the stride ofself tensor.

Tensor.sub

Seetorch.sub().

Tensor.sub_

In-place version ofsub()

Tensor.subtract

Seetorch.subtract().

Tensor.subtract_

In-place version ofsubtract().

Tensor.sum

Seetorch.sum()

Tensor.sum_to_size

Sumthis tensor tosize.

Tensor.svd

Seetorch.svd()

Tensor.swapaxes

Seetorch.swapaxes()

Tensor.swapdims

Seetorch.swapdims()

Tensor.t

Seetorch.t()

Tensor.t_

In-place version oft()

Tensor.tensor_split

Seetorch.tensor_split()

Tensor.tile

Seetorch.tile()

Tensor.to

Performs Tensor dtype and/or device conversion.

Tensor.to_mkldnn

Returns a copy of the tensor intorch.mkldnn layout.

Tensor.take

Seetorch.take()

Tensor.take_along_dim

Seetorch.take_along_dim()

Tensor.tan

Seetorch.tan()

Tensor.tan_

In-place version oftan()

Tensor.tanh

Seetorch.tanh()

Tensor.tanh_

In-place version oftanh()

Tensor.atanh

Seetorch.atanh()

Tensor.atanh_

In-place version ofatanh()

Tensor.arctanh

Seetorch.arctanh()

Tensor.arctanh_

In-place version ofarctanh()

Tensor.tolist

Returns the tensor as a (nested) list.

Tensor.topk

Seetorch.topk()

Tensor.to_dense

Creates a strided copy ofself ifself is not a strided tensor, otherwise returnsself.

Tensor.to_sparse

Returns a sparse copy of the tensor.

Tensor.to_sparse_csr

Convert a tensor to compressed row storage format (CSR).

Tensor.to_sparse_csc

Convert a tensor to compressed column storage (CSC) format.

Tensor.to_sparse_bsr

Convert a tensor to a block sparse row (BSR) storage format of given blocksize.

Tensor.to_sparse_bsc

Convert a tensor to a block sparse column (BSC) storage format of given blocksize.

Tensor.trace

Seetorch.trace()

Tensor.transpose

Seetorch.transpose()

Tensor.transpose_

In-place version oftranspose()

Tensor.triangular_solve

Seetorch.triangular_solve()

Tensor.tril

Seetorch.tril()

Tensor.tril_

In-place version oftril()

Tensor.triu

Seetorch.triu()

Tensor.triu_

In-place version oftriu()

Tensor.true_divide

Seetorch.true_divide()

Tensor.true_divide_

In-place version oftrue_divide_()

Tensor.trunc

Seetorch.trunc()

Tensor.trunc_

In-place version oftrunc()

Tensor.type

Returns the type ifdtype is not provided, else casts this object to the specified type.

Tensor.type_as

Returns this tensor cast to the type of the given tensor.

Tensor.unbind

Seetorch.unbind()

Tensor.unflatten

Seetorch.unflatten().

Tensor.unfold

Returns a view of the original tensor which contains all slices of sizesize fromself tensor in the dimensiondimension.

Tensor.uniform_

Fillsself tensor with numbers sampled from the continuous uniform distribution:

Tensor.unique

Returns the unique elements of the input tensor.

Tensor.unique_consecutive

Eliminates all but the first element from every consecutive group of equivalent elements.

Tensor.unsqueeze

Seetorch.unsqueeze()

Tensor.unsqueeze_

In-place version ofunsqueeze()

Tensor.values

Return the values tensor of asparse COO tensor.

Tensor.var

Seetorch.var()

Tensor.vdot

Seetorch.vdot()

Tensor.view

Returns a new tensor with the same data as theself tensor but of a differentshape.

Tensor.view_as

View this tensor as the same size asother.

Tensor.vsplit

Seetorch.vsplit()

Tensor.where

self.where(condition,y) is equivalent totorch.where(condition,self,y).

Tensor.xlogy

Seetorch.xlogy()

Tensor.xlogy_

In-place version ofxlogy()

Tensor.xpu

Returns a copy of this object in XPU memory.

Tensor.zero_

Fillsself tensor with zeros.