mindspore.Tensor
- class mindspore.Tensor(input_data=None, dtype=None, shape=None, init=None, internal=False, const_arg=False)[source]
Tensor is a data structure that stores an n-dimensional array.
- Parameters
input_data (Union[Tensor, float, int, bool, tuple, list, numpy.ndarray]) – The data to be stored. It can be another Tensor, Python number or NumPy ndarray. Default: None.
dtype (
mindspore.dtype
) – Used to indicate the data type of the output Tensor. The argument should be defined in mindspore.dtype. If it is None, the data type of the output Tensor will be the same as the input_data. Default: None.shape (Union[tuple, list, int]) – Used to indicate the shape of the output Tensor. The argument should be a list of integers, a tuple of integers or an integer. If input_data is available, shape doesn’t need to be set. If None in shape, a tensor of dynamic shape is created, input_data doesn’t need to be set; if None not in shape, a tensor of static shape is created, input_data or init must be set. Default: None.
init (Initializer) – The information of init data. ‘init’ is used for delayed initialization in parallel mode. Usually, it is not recommended to use ‘init’ interface to initialize Tensor in the other conditions. If ‘init’ interface is used to initialize Tensor, the Tensor.init_data API needs to be called to convert Tensor to the actual data. Default: None.
internal (bool) – Whether it is created by the framework. ‘True’ means that the tensor is created by framework. ‘False’ means that the tensor is created by user. Default: False
const_arg (bool) – Whether the tensor is a constant when it is used for the argument of a network. Default: False.
- Outputs:
Tensor.
Examples
>>> import numpy as np >>> import mindspore as ms >>> from mindspore import Tensor >>> from mindspore.common.initializer import One >>> # initialize a tensor with numpy.ndarray >>> t1 = Tensor(np.zeros([1, 2, 3]), ms.float32) >>> print(t1) [[[0. 0. 0.] [0. 0. 0.]]] >>> print(type(t1)) <class 'mindspore.common.tensor.Tensor'> >>> print(t1.shape) (1, 2, 3) >>> print(t1.dtype) Float32 >>> >>> # initialize a tensor with a float scalar >>> t2 = Tensor(0.1) >>> print(t2) 0.1 >>> print(type(t2)) <class 'mindspore.common.tensor.Tensor'> >>> print(t2.shape) () >>> print(t2.dtype) Float32 >>> >>> # initialize a tensor with a tuple >>> t3 = Tensor((1, 2)) >>> print(t3) [1 2] >>> print(type(t3)) <class 'mindspore.common.tensor.Tensor'> >>> print(t3.shape) (2,) >>> print(t3.dtype) Int64 ... >>> # initialize a tensor with init >>> t4 = Tensor(shape = (1, 3), dtype=ms.float32, init=One()) >>> print(t4) [[1. 1. 1.]] >>> print(type(t4)) <class 'mindspore.common.tensor.Tensor'> >>> print(t4.shape) (1, 3) >>> print(t4.dtype) Float32
For details, please refer to |
|
Alias for |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
Multiplies matrix mat and vector vec. |
|
For details, please refer to |
|
For details, please refer to |
|
Check all tensor elements along a given axis evaluate to True. |
|
For details, please refer to |
|
For details, please refer to |
|
Check any tensor element along a given axis evaluate to True. |
|
For details, please refer to |
|
For details, please refer to |
|
Alias for |
|
For details, please refer to |
|
For details, please refer to |
|
Alias for |
|
For details, please refer to |
|
For details, please refer to |
|
Alias for |
|
For details, please refer to |
|
Returns the maximum value with corresponding index. |
|
For details, please refer to |
|
Returns the minimum value with corresponding index. |
|
For details, please refer to |
|
For details, please refer to |
|
Convert tensor to numpy array. |
|
Assign another tensor value to this tensor. |
|
Return a copy of the tensor, cast to a specified type. |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
Converts input tensor dtype to bool. |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
Construct a tensor from an index tensor and a list of tensors to choose from. |
|
Clips (limits) the values in a Tensor. |
|
For details, please refer to |
|
For details, please refer to |
|
Return a copy of the tensor. |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
Return the dtype of the tensor ( |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
Expand the dimension of target tensor to the dimension of input tensor. |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
Converts input tensor dtype to float32. |
|
For details, please refer to |
|
Flush cache data to host if tensor is cache enable. |
|
For details, please refer to |
|
Convert numpy array to Tensor. |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
Converts input tensor dtype to float16. |
|
For details, please refer to |
|
Whether tensor is initialized. |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
Get the tensor format data of this Tensor. |
|
For details, please refer to |
|
Converts input tensor dtype to int32. |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
Judge whether the data type of tensor is a signed data type. |
|
Get the item at the specified index of the tensor. |
|
Insert scalar into a tensor (scalar is cast to tensor's dtype, if possible). |
|
Return the length of one tensor element in bytes. |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
Converts input tensor dtype to int64. |
|
For details, please refer to |
|
For details, please refer to |
|
Return the maximum of a tensor or maximum along an axis. |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
Return the total number of bytes taken by the tensor. |
|
Return the number of tensor dimensions. |
|
Alias for |
|
For details, please refer to |
|
Alias for |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
The name of the function comes from the acronym for "peak to peak". |
|
For details, please refer to |
|
For details, please refer to |
|
Return a contiguous flattened tensor. |
|
For details, please refer to |
|
For details, please refer to |
|
Repeat elements of a tensor. |
|
For details, please refer to |
|
For details, please refer to |
|
Change the shape of the Tensor to the shape of other without changing the data. |
|
Changes shape and size of tensor in-place. |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
Rotate a n-D tensor by 90 degrees in the plane specified by dims axis. |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
Creates a new tensor by subtracting the values from the positions in self tensor indicated by indices, with values from updates. |
|
Finds indices where elements should be inserted to maintain order. |
|
For details, please refer to |
|
Specify whether the tensor is a constant when it is used for the argument of a network. |
|
For details, please refer to |
|
Return a copy of the tensor, cast to int16 type, equivalent to self.astype(mstype.int16). |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
Return the tuple of bytes to step in each dimension when traversing a tensor. |
|
For details, please refer to |
|
For details, please refer to |
|
Return sum of tensor elements over a given axis. |
|
For details, please refer to |
|
Interchange two axes of a tensor. |
|
Return the transposed tensor. |
|
Takes elements from a tensor along an axis. |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
Performs tensor dtype conversion. |
|
Convert a Tensor to COOTensor. |
|
Convert a Tensor to CSRTensor. |
|
Return init_data() and get the tensor format data of this Tensor. |
|
For details, please refer to |
|
Return the sum along diagonals of the tensor. |
|
For details, please refer to |
|
Returns a triangular matrix based on the diagonal. |
|
Alias for Tensor.div() with \(rounding\_mode=None\). |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
For details, please refer to |
|
Compute the variance along the specified axis. |
|
Reshape the tensor according to the input shape. |
|
For details, please refer to |
|
For details, please refer to |