Tensor

Applicable Products

Product

Supported

Atlas A3 training products/Atlas A3 inference products

√

Atlas A2 training products/Atlas A2 inference products

√

Atlas 200I/500 A2 inference products

x

Atlas inference products

x

Atlas training products

x

Function Description

Defines the Tensor constructor.

Prototype

1
Tensor(data, *, tensor_desc: TensorDesc=None)

Parameters

Parameter

Data Type

Value Description

data

Any

Tensor data, which can be a Python list or a NumPy array.

tensor_desc

TensorDesc

Tensor description. When this parameter is specified, if the dtype of the input data is different from that of tensor_desc, the system attempts to forcibly convert the data to the dtype of tensor_desc. If the shape of the input data is different from that of tensor_desc, an error is reported.

Returns

None is returned in normal scenarios.

The DfException exception is reported in abnormal scenarios. You can obtain error_code and message in DfException to view the error code and error information. For details, see DataFlow Error Codes.

Examples

1
2
3
tensor = Tensor([1])
tensor = Tensor(numpy.array([1]))
tensor = Tensor([1], tensor_desc=TensorDesc(dataflow.DT_FLOAT, [1]))

Constraints

None