A `Tensor` is a generalization of vectors and matrices and is easily understood as a multidimensional array. For more information, you can see Introduction to Tensor.

## Data types¶

Data type

dtype

32-bit floating point

`paddle.float32`

64-bit floating point

`paddle.float64`

16-bit floating point

`paddle.float16`

16-bit floating point

`paddle.bfloat16`

64-bit complex

`paddle.complex64`

128-bit complex

`paddle.complex128`

8-bit integer (unsigned)

`paddle.uint8`

8-bit integer (signed)

`paddle.int8`

16-bit integer (signed)

`paddle.int16`

32-bit integer (signed)

`paddle.int32`

64-bit integer (signed)

`paddle.int64`

Boolean

`paddle.bool`

## Tensor class reference¶

### Properties¶

 `T` The transpose of `Tensor`. See paddle.transpose . `block` Tensor’s block. `dtype` Tensor’s data type. `grad` The value of Tensor’s grad. `inplace_version` The inplace version of current Tensor. `is_leaf` Whether Tensor is leaf Tensor. `name` The name of Tensor. `ndim` The dimensions of Tensor. `persistable` The value of Tensor’s persistable. `place` The place of Tensor. `shape` The shape of Tensor. See paddle.shape . `size` The size of Tensor. See paddle.numel . `stop_gradient` The value of Tensor’s stop_gradient. `type` Tensor’s type.

### Methods¶

 `abs` Abs Operator. `acos` Arccosine Operator. `add` Elementwise Add Operator. `add_` Inplace version of `add` API, the output Tensor will be inplaced with input `x`. `add_n` This OP is used to sum one or more Tensor of the input. `addmm` addmm `all` Computes the the `logical and` of tensor elements over the given dimension. `allclose` This operator checks if all \(x\) and \(y\) satisfy the condition: `angle` Element-wise angle of complex numbers. `any` Computes the the `logical or` of tensor elements over the given dimension. `argmax` This OP computes the indices of the max elements of the input tensor’s element along the provided axis. `argmin` This OP computes the indices of the min elements of the input tensor’s element along the provided axis. `argsort` This OP sorts the input along the given axis, and returns the corresponding index tensor for the sorted output values. `as_complex` Transform a real tensor to a complex tensor. `as_real` Transform a complex tensor to a real tensor. `asin` Arcsine Operator. `astype` Cast a Tensor to a specified data type. `atan` Arctangent Operator. `backward` Run backward of current Graph which starts from current Tensor. `bitwise_and` It operates `bitwise_and` on Tensor `X` and `Y` . `bitwise_not` It operates `bitwise_not` on Tensor `X` . `bitwise_or` It operates `bitwise_or` on Tensor `X` and `Y` . `bitwise_xor` It operates `bitwise_xor` on Tensor `X` and `Y` . `bmm` Applies batched matrix multiplication to two tensors. `broadcast_shape` The function returns the shape of doing operation with broadcasting on tensors of x_shape and y_shape, please refer to user_guide_broadcasting for more details. `broadcast_tensors` This OP broadcast a list of tensors following broadcast semantics `broadcast_to` Broadcast the input tensor to a given shape. `cast` This OP takes in the Tensor `x` with `x.dtype` and casts it to the output with `dtype`. `ceil` Ceil Operator. `ceil_` Inplace version of `ceil` API, the output Tensor will be inplaced with input `x`. `cholesky` Computes the Cholesky decomposition of one symmetric positive-definite matrix or batches of symmetric positive-definite matrice. `chunk` Split the input tensor into multiple sub-Tensors. `clear_grad` The alias of clear_gradient(). `clear_gradient` Only for Tensor that has gradient, normally we use this for Parameters since other temporary Tensor doesen’t has gradient. `clip` This operator clip all elements in input into the range [ min, max ] and return a resulting tensor as the following equation: `clip_` Inplace version of `clip` API, the output Tensor will be inplaced with input `x`. `clone` Returns a new Tensor, which is clone of origin Tensor, and it remains in the current graph. `concat` This OP concatenates the input along the axis. `cond` Computes the condition number of a matrix or batches of matrices with respect to a matrix norm `p`. `conj` This function computes the conjugate of the Tensor elementwisely. `copy_` `cos` Cosine Operator. `cosh` Cosh Activation Operator. `cpu` Returns a copy of this Tensor in CPU memory. `cross` Computes the cross product between two tensors along an axis. `cuda` Returns a copy of this Tensor in GPU memory. `cumprod` Compute the cumulative product of the input tensor x along a given dimension dim. `cumsum` The cumulative sum of the elements along a given axis. `detach` Returns a new Tensor, detached from the current graph. `diagonal` This OP computes the diagonals of the input tensor x. `digamma` Calculates the digamma of the given input tensor, element-wise. `dim` `dist` This OP returns the p-norm of (x - y). `divide` Divide two tensors element-wise. `dot` This operator calculates inner product for vectors. `diff` Computes the n-th forward difference along the given axis. `eigvals` Compute the eigenvalues of one or more general matrices. `equal` This layer returns the truth value of \(x == y\) elementwise. `equal_all` This OP returns the truth value of \(x == y\). `erf` Erf Operator For more details, see [Error function](https://en.wikipedia.org/wiki/Error_function). `exp` Exp Operator. `exp_` Inplace version of `exp` API, the output Tensor will be inplaced with input `x`. `expand` Expand the input tensor to a given shape. `expand_as` Expand the input tensor `x` to the same shape as the input tensor `y`. `fill_` Notes: `fill_diagonal_` Notes: `fill_diagonal_tensor` This function fill the source Tensor y into the x Tensor’s diagonal. `fill_diagonal_tensor_` Notes: `flatten` Flatten op `flatten_` Inplace version of `flatten` API, the output Tensor will be inplaced with input `x`. `flip` Reverse the order of a n-D tensor along given axis in axis. `floor` Floor Activation Operator. `floor_` Inplace version of `floor` API, the output Tensor will be inplaced with input `x`. `floor_divide` Floor divide two tensors element-wise. `floor_mod` Mod two tensors element-wise. `gather` Output is obtained by gathering entries of `axis` of `x` indexed by `index` and concatenate them together. `gather_nd` This function is actually a high-dimensional extension of `gather` and supports for simultaneous indexing by multiple axes. `gradient` `greater_equal` This OP returns the truth value of \(x >= y\) elementwise, which is equivalent function to the overloaded operator >=. `greater_than` This OP returns the truth value of \(x > y\) elementwise, which is equivalent function to the overloaded operator >. `histogram` Computes the histogram of a tensor. `imag` Returns a new tensor containing imaginary values of input tensor. `increment` The OP is usually used for control flow to increment the data of `x` by an amount `value`. `index_sample` IndexSample Layer `index_select` Returns a new tensor which indexes the `input` tensor along dimension `axis` using the entries in `index` which is a Tensor. `inverse` Takes the inverse of the square matrix. `isclose` This operator checks if all \(x\) and \(y\) satisfy the condition: `is_empty` Test whether a Tensor is empty. `is_tensor` This function tests whether input object is a paddle.Tensor. `isfinite` Return whether every element of input tensor is finite number or not. `isinf` Return whether every element of input tensor is +/-INF or not. `isnan` Return whether every element of input tensor is NaN or not. `item` Convert element at specific position in Tensor into Python scalars. `kron` Kron Operator. `less_equal` This OP returns the truth value of \(x <= y\) elementwise, which is equivalent function to the overloaded operator <=. `less_than` This OP returns the truth value of \(x < y\) elementwise, which is equivalent function to the overloaded operator <. `lgamma` Lgamma Operator. `log` Calculates the natural log of the given input tensor, element-wise. `log10` Calculates the log to the base 10 of the given input tensor, element-wise. `log1p` Calculates the natural log of the given input tensor, element-wise. `log2` Calculates the log to the base 2 of the given input tensor, element-wise. `logical_and` `logical_and` operator computes element-wise logical AND on `x` and `y`, and returns `out`. `logical_not` `logical_not` operator computes element-wise logical NOT on `x`, and returns `out`. `logical_or` `logical_or` operator computes element-wise logical OR on `x` and `y`, and returns `out`. `logical_xor` `logical_xor` operator computes element-wise logical XOR on `x` and `y`, and returns `out`. `logsumexp` This OP calculates the log of the sum of exponentials of `x` along `axis` . `masked_select` This OP Returns a new 1-D tensor which indexes the input tensor according to the `mask` which is a tensor with data type of bool. `matmul` Applies matrix multiplication to two tensors. `matrix_power` Computes the n-th power of a square matrix or a batch of square matrices. `max` Computes the maximum of tensor elements over the given axis. `maximum` Compare two tensors and returns a new tensor containing the element-wise maxima. `fmax` Compares the elements at the corresponding positions of the two tensors and returns a new tensor containing the maximum value of the element. `mean` Computes the mean of the input tensor’s elements along `axis`. `median` Compute the median along the specified axis. `min` Computes the minimum of tensor elements over the given axis `minimum` Compare two tensors and returns a new tensor containing the element-wise minima. `fmin` Compares the elements at the corresponding positions of the two tensors and returns a new tensor containing the minimum value of the element. `mm` Applies matrix multiplication to two tensors. `inner` Inner product of two input Tensor. `outer` Outer product of two Tensors. `cov` Estimate the covariance matrix of the input variables, given data and weights. `lu` Computes the LU factorization of an N-D(N>=2) matrix x. `lu_unpack` Unpack L U and P to single matrix tensor . `cholesky_solve` Solves a linear system of equations A @ X = B, given A’s Cholesky factor matrix u and matrix B. `mod` Mod two tensors element-wise. `multiplex` Based on the given index parameter, the OP selects a specific row from each input Tensor to construct the output Tensor. `multiply` Elementwise Mul Operator. `mv` Performs a matrix-vector product of the matrix x and the vector vec. `ndimension` `neg` This function computes the negative of the Tensor elementwisely. `nonzero` Return a tensor containing the indices of all non-zero elements of the input tensor. `norm` Returns the matrix norm (Frobenius) or vector norm (the 1-norm, the Euclidean or 2-norm, and in general the p-norm for p > 0) of a given tensor. `not_equal` This OP returns the truth value of \(x != y\) elementwise, which is equivalent function to the overloaded operator !=. `numel` Returns the number of elements for a tensor, which is a int64 Tensor with shape  in static mode or a scalar value in imperative mode `numpy` Returns a numpy array shows the value of current Tensor. `pin_memory` Returns a copy of this Tensor in pin memory. `pow` Compute the power of tensor elements. `prod` Compute the product of tensor elements over the given axis. `rank` The OP returns the number of dimensions for a tensor, which is a 0-D int32 Tensor. `real` Returns a new tensor containing real values of the input tensor. `reciprocal` Reciprocal Activation Operator. `reciprocal_` Inplace version of `reciprocal` API, the output Tensor will be inplaced with input `x`. `register_hook` Registers a backward hook for current Tensor. `remainder` Mod two tensors element-wise. `repeat_interleave` Returns a new tensor which repeats the `x` tensor along dimension `axis` using the entries in `repeats` which is a int or a Tensor. `reshape` This operator changes the shape of `x` without changing its data. `reshape_` Inplace version of `reshape` API, the output Tensor will be inplaced with input `x`. `reverse` Reverse the order of a n-D tensor along given axis in axis. `roll` Roll the x tensor along the given axis(axes). `round` The OP rounds the values in the input to the nearest integer value. `round_` Inplace version of `round` API, the output Tensor will be inplaced with input `x`. `rsqrt` Rsqrt Activation Operator. `rsqrt_` Inplace version of `rsqrt` API, the output Tensor will be inplaced with input `x`. `scale` Scale operator. `scale_` Inplace version of `scale` API, the output Tensor will be inplaced with input `x`. `scatter` Scatter Layer Output is obtained by updating the input on selected indices based on updates. `scatter_` Inplace version of `scatter` API, the output Tensor will be inplaced with input `x`. `scatter_nd` Scatter_nd Layer `scatter_nd_add` Scatter_nd_add Layer `set_value` Notes: `shard_index` Reset the values of input according to the shard it beloning to. Every value in input must be a non-negative integer, and the parameter index_num represents the integer above the maximum value of input. Thus, all values in input must be in the range [0, index_num) and each value can be regarded as the offset to the beginning of the range. The range is further split into multiple shards. Specifically, we first compute the shard_size according to the following formula, which represents the number of integers each shard can hold. So for the i’th shard, it can hold values in the range [i*shard_size, (i+1)*shard_size). ::. `sign` This OP returns sign of every element in x: 1 for positive, -1 for negative and 0 for zero. `sin` Sine Activation Operator. `sinh` Sinh Activation Operator. `slice` This operator produces a slice of `input` along multiple axes. `solve` Computes the solution of a square system of linear equations with a unique solution for input ‘X’ and ‘Y’. `sort` This OP sorts the input along the given axis, and returns the sorted output tensor. `split` Split the input tensor into multiple sub-Tensors. `sqrt` Sqrt Activation Operator. `sqrt_` Inplace version of `sqrt` API, the output Tensor will be inplaced with input `x`. `square` The OP square each elements of the inputs. `squeeze` This OP will squeeze the dimension(s) of size 1 of input tensor x’s shape. `squeeze_` Inplace version of `squeeze` API, the output Tensor will be inplaced with input `x`. `stack` This OP stacks all the input tensors `x` along `axis` dimemsion. `stanh` stanh activation. `std` Computes the standard-deviation of `x` along `axis` . `strided_slice` This operator produces a slice of `x` along multiple axes. `subtract` Substract two tensors element-wise. `subtract_` Inplace version of `subtract` API, the output Tensor will be inplaced with input `x`. `sum` Computes the sum of tensor elements over the given dimension. `t` Transpose <=2-D tensor. `tanh` Tanh Activation Operator. `tanh_` Inplace version of `tanh` API, the output Tensor will be inplaced with input `x`. `tile` Construct a new Tensor by repeating `x` the number of times given by `repeat_times`. `tolist` Notes: `topk` This OP is used to find values and indices of the k largest or smallest at the optional axis. `trace` trace `transpose` Permute the data dimensions of input according to perm. `trunc` This API is used to returns a new tensor with the truncated integer values of input. `unbind` Removes a tensor dimension, then split the input tensor into multiple sub-Tensors. `uniform_` This is the inplace version of OP `uniform`, which returns a Tensor filled with random values sampled from a uniform distribution. `unique` Returns the unique elements of x in ascending order. `unique_consecutive` Eliminates all but the first element from every consecutive group of equivalent elements. `unsqueeze` Insert single-dimensional entries to the shape of input Tensor `x`. `unsqueeze_` Inplace version of `unsqueeze` API, the output Tensor will be inplaced with input `x`. `unstack` alias_main paddle.unstack `value` `var` Computes the variance of `x` along `axis` . `where` Return a tensor of elements selected from either \$x\$ or \$y\$, depending on \$condition\$. `zero_` Notes: `is_complex` Return whether x is a tensor of complex data type(complex64 or complex128). `is_integer` Return whether x is a tensor of integeral data type.