Tensor Constructor

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

Atlas A2 training product/Atlas A2 inference product

Atlas 200I/500 A2 inference product

Atlas inference product

Atlas training product

Function Usage

Creates a tensor object.

Prototype

1
Tensor(data: Optional[UnionTensorDataType] = None, file_path: Optional[str] = None, data_type: Optional[DataType] = DataType.DT_FLOAT, format: Optional[Format] = Format.FORMAT_ND, shape: Optional[List[int]] = None)

Parameters

Parameter

Input/Output

Description

data

Input

Data list.

file_path

Input

Path from which data is read.

data_type

Input

Data type. The default value is DT_FLOAT.

format

Input

Data format. The default value is FORMAT_ND.

shape

Input

Shape dimension list. None indicates a scalar.

Returns

None

Restrictions

  • Either data or file_path must be specified.
  • If both are provided, RuntimeError is thrown.
  • The shape must be a list of integers.
  • The DT_DOUBLE type is not supported in the Python Tensor constructor.

Example

1
2
3
4
5
# Create from data.
tensor1 = Tensor(data=[1.0, 2.0, 3.0], data_type=DataType.DT_FLOAT, format=Format.FORMAT_ND, shape=[3])

# Create from a file.
tensor2 = Tensor(file_path="/path/to/file", data_type=DataType.DT_FLOAT, format=Format.FORMAT_ND, shape=[2, 2])