paddle.Tensor¶
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¶
PaddlePaddle defines the following Tensor types:
| Data type | dtype | 
|---|---|
| 32-bit floating point | 
 | 
| 64-bit floating point | 
 | 
| 16-bit floating point | 
 | 
| 16-bit floating point | 
 | 
| 64-bit complex | 
 | 
| 128-bit complex | 
 | 
| 8-bit integer (unsigned) | 
 | 
| 8-bit integer (signed) | 
 | 
| 16-bit integer (signed) | 
 | 
| 32-bit integer (signed) | 
 | 
| 64-bit integer (signed) | 
 | 
| Boolean | 
 | 
Tensor class reference¶
Properties¶
| 
 | The transpose of  | 
| 
 | Tensor’s block. | 
| 
 | Tensor’s data type. | 
| 
 | The value of Tensor’s grad. | 
| 
 | The inplace version of current Tensor. | 
| 
 | Whether Tensor is leaf Tensor. | 
| 
 | The name of Tensor. | 
| 
 | The dimensions of Tensor. | 
| 
 | The value of Tensor’s persistable. | 
| 
 | The place of Tensor. | 
| 
 | The shape of Tensor. See paddle.shape . | 
| 
 | The size of Tensor. See paddle.numel . | 
| 
 | The value of Tensor’s stop_gradient. | 
| 
 | Tensor’s type. | 
Methods¶
| 
 | Abs Operator. | 
| 
 | Arccosine Operator. | 
| 
 | Elementwise Add Operator. | 
| 
 | Inplace version of  | 
| 
 | Sum one or more Tensor of the input. | 
| 
 | addmm | 
| 
 | Computes the  | 
| 
 | This operator checks if all \(x\) and \(y\) satisfy the condition: | 
| 
 | Element-wise angle of complex numbers. | 
| 
 | Computes the  | 
| 
 | Computes the indices of the max elements of the input tensor’s element along the provided axis. | 
| 
 | Computes the indices of the min elements of the input tensor’s element along the provided axis. | 
| 
 | Sorts the input along the given axis, and returns the corresponding index tensor for the sorted output values. | 
| 
 | Transform a real tensor to a complex tensor. | 
| 
 | Transform a complex tensor to a real tensor. | 
| 
 | Arcsine Operator. | 
| 
 | Cast a Tensor to a specified data type. | 
| 
 | Arctangent Operator. | 
| 
 | Run backward of current Graph which starts from current Tensor. | 
| 
 | It operates  | 
| 
 | It operates  | 
| 
 | It operates  | 
| 
 | It operates  | 
| 
 | Applies batched matrix multiplication to two tensors. | 
| 
 | 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. | 
| 
 | This OP broadcast a list of tensors following broadcast semantics | 
| 
 | Broadcast the input tensor to a given shape. | 
| 
 | This API is used to find the index of the corresponding 1D tensor sorted_sequence in the innermost dimension based on the given x. | 
| 
 | This OP takes in the Tensor  | 
| 
 | Ceil Operator. | 
| 
 | Inplace version of  | 
| 
 | Computes the Cholesky decomposition of one symmetric positive-definite matrix or batches of symmetric positive-definite matrice. | 
| 
 | Split the input tensor into multiple sub-Tensors. | 
| 
 | The alias of clear_gradient(). | 
| 
 | |
| 
 | This operator clip all elements in input into the range [ min, max ] and return a resulting tensor as the following equation: | 
| 
 | Inplace version of  | 
| 
 | |
| 
 | Concatenates the input along the axis. | 
| 
 | Computes the condition number of a matrix or batches of matrices with respect to a matrix norm  | 
| 
 | This function computes the conjugate of the Tensor elementwisely. | 
| 
 | |
| 
 | Cosine Operator. | 
| 
 | Cosh Activation Operator. | 
| 
 | Counts the number of non-zero values in the tensor x along the specified axis. | 
| 
 | |
| 
 | Computes the cross product between two tensors along an axis. | 
| 
 | |
| 
 | Compute the cumulative product of the input tensor x along a given dimension dim. | 
| 
 | The cumulative sum of the elements along a given axis. | 
| 
 | |
| 
 | This OP computes the diagonals of the input tensor x. | 
| 
 | Calculates the digamma of the given input tensor, element-wise. | 
| 
 | |
| 
 | This OP returns the p-norm of (x - y). | 
| 
 | Divide two tensors element-wise. | 
| 
 | This operator calculates inner product for vectors. | 
| 
 | Computes the n-th forward difference along the given axis. | 
| 
 | Compute the eigenvalues of one or more general matrices. | 
| 
 | This layer returns the truth value of \(x == y\) elementwise. | 
| 
 | Returns the truth value of \(x == y\). | 
| 
 | Erf Operator For more details, see Error function. | 
| 
 | Exp Operator. | 
| 
 | Inplace version of  | 
| 
 | Expand the input tensor to a given shape. | 
| 
 | Expand the input tensor  | 
| 
 | Notes: | 
| 
 | Note This API is ONLY available in Dygraph mode. | 
| 
 | This function fill the source Tensor y into the x Tensor’s diagonal. | 
| 
 | Note This API is ONLY available in Dygraph mode. | 
| 
 | Flattens a contiguous range of axes in a tensor according to start_axis and stop_axis. | 
| 
 | Inplace version of  | 
| 
 | Reverse the order of a n-D tensor along given axis in axis. | 
| 
 | Floor Activation Operator. | 
| 
 | Inplace version of  | 
| 
 | Floor divide two tensors element-wise. | 
| 
 | Mod two tensors element-wise. | 
| 
 | Output is obtained by gathering entries of  | 
| 
 | This function is actually a high-dimensional extension of  | 
| 
 | |
| 
 | Returns the truth value of \(x >= y\) elementwise, which is equivalent function to the overloaded operator >=. | 
| 
 | Returns the truth value of \(x > y\) elementwise, which is equivalent function to the overloaded operator >. | 
| 
 | Computes the histogram of a tensor. | 
| 
 | Returns a new tensor containing imaginary values of input tensor. | 
| 
 | The API is usually used for control flow to increment the data of  | 
| 
 | IndexSample Layer | 
| 
 | Returns a new tensor which indexes the  | 
| 
 | Takes the inverse of the square matrix. | 
| 
 | This operator checks if all \(x\) and \(y\) satisfy the condition: | 
| 
 | Test whether a Tensor is empty. | 
| 
 | Tests whether input object is a paddle.Tensor. | 
| 
 | Return whether every element of input tensor is finite number or not. | 
| 
 | Return whether every element of input tensor is +/-INF or not. | 
| 
 | Return whether every element of input tensor is NaN or not. | 
| 
 | Convert element at specific position in Tensor into Python scalars. | 
| 
 | Kron Operator. | 
| 
 | Returns the truth value of \(x <= y\) elementwise, which is equivalent function to the overloaded operator <=. | 
| 
 | Returns the truth value of \(x < y\) elementwise, which is equivalent function to the overloaded operator <. | 
| 
 | Calculates the lgamma of the given input tensor, element-wise. | 
| 
 | Calculates the natural log of the given input Tensor, element-wise. | 
| 
 | Calculates the log to the base 10 of the given input tensor, element-wise. | 
| 
 | Calculates the natural log of the given input tensor, element-wise. | 
| 
 | Calculates the log to the base 2 of the given input tensor, element-wise. | 
| 
 | The logarithm of the cumulative summation of the exponentiation of the elements along a given axis. | 
| 
 | 
 | 
| 
 | 
 | 
| 
 | 
 | 
| 
 | 
 | 
| 
 | Calculates the log of the sum of exponentials of  | 
| 
 | Returns a new 1-D tensor which indexes the input tensor according to the  | 
| 
 | Applies matrix multiplication to two tensors. | 
| 
 | Computes the n-th power of a square matrix or a batch of square matrices. | 
| 
 | Computes the maximum of tensor elements over the given axis. | 
| 
 | Compare two tensors and returns a new tensor containing the element-wise maxima. | 
| 
 | Compares the elements at the corresponding positions of the two tensors and returns a new tensor containing the maximum value of the element. | 
| 
 | Computes the mean of the input tensor’s elements along  | 
| 
 | Compute the median along the specified axis. | 
| 
 | Compute the median along the specified axis, while ignoring NaNs. | 
| 
 | Computes the minimum of tensor elements over the given axis | 
| 
 | Compare two tensors and return a new tensor containing the element-wise minima. | 
| 
 | Compares the elements at the corresponding positions of the two tensors and returns a new tensor containing the minimum value of the element. | 
| 
 | Applies matrix multiplication to two tensors. | 
| 
 | Inner product of two input Tensor. | 
| 
 | Outer product of two Tensors. | 
| 
 | Estimate the covariance matrix of the input variables, given data and weights. | 
| 
 | Computes the LU factorization of an N-D(N>=2) matrix x. | 
| 
 | Unpack L U and P to single matrix tensor . | 
| 
 | Solves a linear system of equations A @ X = B, given A’s Cholesky factor matrix u and matrix B. | 
| 
 | Mod two tensors element-wise. | 
| 
 | Based on the given index parameter, the OP selects a specific row from each input Tensor to construct the output Tensor. | 
| 
 | multiply two tensors element-wise. | 
| 
 | Performs a matrix-vector product of the matrix x and the vector vec. | 
| 
 | |
| 
 | This function computes the negative of the Tensor elementwisely. | 
| 
 | Return a tensor containing the indices of all non-zero elements of the input tensor. | 
| 
 | 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. | 
| 
 | Returns the truth value of \(x != y\) elementwise, which is equivalent function to the overloaded operator !=. | 
| 
 | Returns the number of elements for a tensor, which is a int64 Tensor with shape [1] in static mode or a scalar value in imperative mode. | 
| 
 | |
| 
 | |
| 
 | Compute the power of Tensor elements. | 
| 
 | Compute the product of tensor elements over the given axis. | 
| 
 | Returns the number of dimensions for a tensor, which is a 0-D int32 Tensor. | 
| 
 | Returns a new Tensor containing real values of the input Tensor. | 
| 
 | Reciprocal Activation Operator. | 
| 
 | Inplace version of  | 
| 
 | Registers a backward hook for current Tensor. | 
| 
 | Mod two tensors element-wise. | 
| 
 | Returns a new tensor which repeats the  | 
| 
 | Changes the shape of  | 
| 
 | Inplace version of  | 
| 
 | Reverse the order of a n-D tensor along given axis in axis. | 
| 
 | Roll the x tensor along the given axis(axes). | 
| 
 | The OP rounds the values in the input to the nearest integer value. | 
| 
 | Inplace version of  | 
| 
 | Rsqrt Activation Operator. | 
| 
 | Inplace version of  | 
| 
 | Scale operator. | 
| 
 | Inplace version of  | 
| 
 | Scatter Layer Output is obtained by updating the input on selected indices based on updates. | 
| 
 | Inplace version of  | 
| 
 | Scatter_nd Layer | 
| 
 | Output is obtained by applying sparse addition to a single value or slice in a Tensor. | 
| 
 | Notes: | 
| 
 | 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). ::. | 
| 
 | Returns sign of every element in x: 1 for positive, -1 for negative and 0 for zero. | 
| 
 | For complex tensor, this API returns a new tensor whose elements have the same angles as the corresponding elements of input and absolute values of one. | 
| 
 | Sine Activation Operator. | 
| 
 | Sinh Activation Operator. | 
| 
 | This operator produces a slice of  | 
| 
 | Computes the solution of a square system of linear equations with a unique solution for input ‘X’ and ‘Y’. | 
| 
 | Sorts the input along the given axis, and returns the sorted output tensor. | 
| 
 | Split the input tensor into multiple sub-Tensors. | 
| 
 | Sqrt Activation Operator. | 
| 
 | Inplace version of  | 
| 
 | The OP square each elements of the inputs. | 
| 
 | Squeeze the dimension(s) of size 1 of input tensor x’s shape. | 
| 
 | Inplace version of  | 
| 
 | Stacks all the input tensors  | 
| 
 | stanh activation. | 
| 
 | Computes the standard-deviation of  | 
| 
 | This operator produces a slice of  | 
| 
 | Substract two tensors element-wise. | 
| 
 | Inplace version of  | 
| 
 | Computes the sum of tensor elements over the given dimension. | 
| 
 | Transpose <=2-D tensor. | 
| 
 | Returns a new tensor with the elements of input tensor x at the given index. | 
| 
 | Tanh Activation Operator. | 
| 
 | Inplace version of  | 
| 
 | Construct a new Tensor by repeating  | 
| 
 | Note This API is ONLY available in Dygraph mode. | 
| 
 | Return values and indices of the k largest or smallest at the optional axis. | 
| 
 | Computes the sum along diagonals of the input tensor x. | 
| 
 | Permute the data dimensions of input according to perm. | 
| 
 | This API is used to returns a new tensor with the truncated integer values of input. | 
| 
 | This API is used to return the fractional portion of each element in input. | 
| 
 | Removes a tensor dimension, then split the input tensor into multiple sub-Tensors. | 
| 
 | This is the inplace version of OP  | 
| 
 | Returns the unique elements of x in ascending order. | 
| 
 | Eliminates all but the first element from every consecutive group of equivalent elements. | 
| 
 | Insert single-dimensional entries to the shape of input Tensor  | 
| 
 | Inplace version of  | 
| 
 | 
 | 
| 
 | |
| 
 | Computes the variance of  | 
| 
 | Return a Tensor of elements selected from either  | 
| 
 | Notes: | 
| 
 | Return whether x is a tensor of complex data type(complex64 or complex128). | 
| 
 | Return whether x is a tensor of integeral data type. | 
