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¶
|
Perform elementwise abs for input x. |
|
Acos Activation Operator. |
|
Elementwise Add Operator. |
|
Inplace version of |
|
Sum one or more Tensor of the input. |
|
addmm |
|
Computes the |
|
Check 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. |
|
This is the inplace version of api |
|
Apply |
|
Apply |
|
Apply |
|
Apply |
|
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. |
|
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. |
|
Take in the Tensor |
|
Ceil Operator. |
|
Inplace version of |
|
Computes the Cholesky decomposition of one symmetric positive-definite matrix or batches of symmetric positive-definite matrices. |
|
Split the input tensor into multiple sub-Tensors. |
|
The alias of clear_gradient(). |
|
Only for Tensor that has gradient, normally we use this for Parameters since other temporary Tensor doesen’t has 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 |
|
Returns a new Tensor, which is clone of origin Tensor, and it remains in the current graph. |
|
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. |
|
Returns a new Tensor, detached from the current graph. |
|
Computes the diagonals of the input tensor x. |
|
Calculates the digamma of the given input tensor, element-wise. |
|
|
|
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\). |
|
The error function. |
|
Computes exp of x element-wise with a natural number e as the base. |
|
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 and rounds the quotinents to the nearest integer toward zero. |
|
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. |
|
Check 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. |
|
Tests if each element of x is in test_x. |
|
Return whether every element of input tensor is +/-INF or not. |
|
Return whether every element of input tensor is NaN or not. |
|
Tests if each element of input is negative infinity or not. |
|
Tests if each element of input is positive infinity or not. |
|
Tests if each element of input is a real number or not. |
|
Convert element at specific position in Tensor into Python scalars. |
|
Compute the Kronecker product of two tensors, a composite tensor made of blocks of the second tensor scaled by the first. |
|
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. |
|
Compute element-wise logical AND on |
|
|
|
|
|
|
|
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. |
|
Replaces NaN, positive infinity, and negative infinity values in input tensor. |
|
|
|
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 (the Frobenius norm, the nuclear norm and p-norm) or vector norm (the 1-norm, the Euclidean or 2-norm, and in general the p-norm) 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 0-D int64 Tensor with shape []. |
|
Returns a numpy array shows the value of current Tensor. |
|
|
|
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). |
|
Round 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 belongs 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. |
|
Calculate the normalized sinc of |
|
Inplace version of |
|
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. |
|
Split the input tensor into multiple sub-Tensors along the vertical axis, which is equivalent to |
|
Sqrt Activation Operator. |
|
Inplace version of |
|
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 |
|
Subtract 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 |
|
Performs Tensor dtype and/or device conversion. |
|
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 |
|
This layer unstacks input Tensor |
|
|
|
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 integral data type. |
|
The function used to decompose a floating point number into mantissa and exponent. |
|
Integrate along the given axis using the composite trapezoidal rule. |
|
Integrate along the given axis using the composite trapezoidal rule. |
|
Generate a Vandermonde matrix. |
|
Calculate the length of the hypotenuse of a right-angle triangle. |
|
Inplace version of |
|
Embed the values of Tensor |
|
Compute combinations of length r of the given tensor. |