Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

torch.

cumprod (input, dim, out=None, dtype=None) → Tensor


Returns the cumulative product of elements of  input  in the dimension  dim .

For example, if  input  is a vector of size N, the result will also be a vector of
size N, with elements.

y_i = x_1 \times x_2\times x_3\times \dots \times x_iyi=x1×x2×x3×⋯


×xi
Parameters
 input (Tensor) – the input tensor.
 dim (int) – the dimension to do the operation over
 dtype ( torch.dtype , optional) – the desired data type of returned tensor. If
specified, the input tensor is casted to  dtype  before the operation is
performed. This is useful for preventing data type overflows. Default: None.
 out (Tensor, optional) – the output tensor.
Example:

>>> a = torch.randn(10)
>>> a
tensor([ 0.6001, 0.2069, -0.1919, 0.9792, 0.6727, 1.0062, 0.4126,
-0.2129, -0.4206, 0.1968])
>>> torch.cumprod(a, dim=0)
tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0158, -0.0065,
0.0014, -0.0006, -0.0001])

>>> a[5] = 0.0


>>> torch.cumprod(a, dim=0)
tensor([ 0.6001, 0.1241, -0.0238, -0.0233, -0.0157, -0.0000, -0.0000,
0.0000, -0.0000, -0.0000])

torch.flatten (input, start_dim=0, end_dim=-1) → Tensor


Flattens a contiguous range of dims in a tensor.

Parameters
 input (Tensor) – the input tensor.
 start_dim (int) – the first dim to flatten
 end_dim (int) – the last dim to flatten
Example:

>>> t = torch.tensor([[[1, 2],


[3, 4]],
[[5, 6],
[7, 8]]])
>>> torch.flatten(t)
tensor([1, 2, 3, 4, 5, 6, 7, 8])
>>> torch.flatten(t, start_dim=1)
tensor([[1, 2, 3, 4],
[5, 6, 7, 8]])
torch.histc (input, bins=100, min=0, max=0, out=None) → Tensor
Computes the histogram of a tensor.

The elements are sorted into equal width bins between  min  and  max .
If  min  and  max  are both zero, the minimum and maximum values of the data
are used.

Parameters
 input (Tensor) – the input tensor.
 bins (int) – number of histogram bins
 min (int) – lower end of the range (inclusive)
 max (int) – upper end of the range (inclusive)
 out (Tensor, optional) – the output tensor.
Returns
Histogram represented as a tensor

Return type
Tensor

Example:

>>> torch.histc(torch.tensor([1., 2, 1]), bins=4, min=0, max=3)


tensor([ 0., 2., 1., 0.]

torch.flip (input, dims) → Tensor


Reverse the order of a n-D tensor along given axis in dims.

Parameters
 input (Tensor) – the input tensor.
 dims (a list or tuple) – axis to flip on
Example:

>>> x = torch.arange(8).view(2, 2, 2)
>>> x
tensor([[[ 0, 1],
[ 2, 3]],

[[ 4, 5],
[ 6, 7]]])
>>> torch.flip(x, [0, 1])
tensor([[[ 6, 7],
[ 4, 5]],

[[ 2, 3],
[ 0, 1]]])
torch.trunc (input, out=None) → Tensor
Returns a new tensor with the truncated integer values of the elements
of  input .

Parameters
 input (Tensor) – the input tensor.
 out (Tensor, optional) – the output tensor.
Example:

>>> a = torch.randn(4)
>>> a
tensor([ 3.4742, 0.5466, -0.8008, -0.9079])
>>> torch.trunc(a)
tensor([ 3., 0., -0., -0.])

You might also like