---
title: Tensor
description: "| 产品 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/others/dataflowdevg/dfrefp_23_0031.html
sourcePath: /source/zh/canncommercial/900/others/dataflowdevg/dfrefp_23_0031.html
indexId: d27b4d29f2b5058d667a5fd1cba27b3c1f686cf1c0f067ebab9eba0007f14b2069
---
# Tensor

#### 产品支持情况

| 产品 | 是否支持 |
| --- | --- |
| Atlas A3 训练系列产品 / Atlas A3 推理系列产品 | √ |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | √ |
| Atlas 200I/500 A2 推理产品 | x |
| Atlas 推理系列产品 | x |
| Atlas 训练系列产品 | x |


#### 函数功能

Tensor的构造函数。


#### 函数原型

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


#### 参数说明

| 参数名称 | 数据类型 | 取值说明 |
| --- | --- | --- |
| data | Any | tensor的数据，可以是Python的list，也可以是numpy。 |
| tensor\_desc | TensorDesc | 表示tensor的描述，当指定时，如果传入的data的dtype与tensor\_desc的dtype不一致，会尝试强转到tensor\_desc的dtype的类型，如果传入的data的shape与tensor\_desc的shape不一致，会报错。 |


#### 返回值

正常场景下返回None。

异常情况下会抛出DfException异常。可以通过捕捉异常获取DfException中的error_code与message查看具体的错误码及错误信息。详细信息请参考DataFlow错误码。


#### 调用示例

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


#### 约束说明

无
