mindspore.ops.tuple_to_array
- mindspore.ops.tuple_to_array(input_x)[source]
Converts a tuple to a tensor.
If the type of the first number in the tuple is integer, the data type of the output tensor is int. Otherwise, the data type of the output tensor is float.
- Parameters
input_x (tuple) – A tuple of numbers. These numbers have the same type. Only constant value is allowed. The shape is \((N,*)\) where \(*\) means any number of additional dimensions.
- Returns
Tensor, if the input tuple contains N numbers, then the shape of the output tensor is (N,).
- Raises
TypeError – If input_x is not a tuple.
ValueError – If length of input_x is less than or equal to 0.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> input_x = (1,2,3) >>> print(type(input_x)) <class 'tuple'> >>> output = ops.tuple_to_array(input_x) >>> print(type(output)) <class 'mindspore.common.tensor.Tensor'> >>> print(output) [1 2 3]