---
title: SetDataType
description: "设置Tensor的数据类型。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/maintenref/basicdataapi/atlasopapi_07_00204.html
sourcePath: /source/zh/canncommercial/900/maintenref/basicdataapi/atlasopapi_07_00204.html
indexId: 83dc985d2f95d53dad26b105ae25dc2fd8fb2ca22a75d5f0398f773ed24dac2078
---
# SetDataType

#### 函数功能

设置Tensor的数据类型。


#### 函数原型

void SetDataType(const ge::DataType data_type)


#### 参数说明

| 参数 | 输入/输出 | 说明 |
| --- | --- | --- |
| data\_type | 输入 | 需要设置的Tensor的数据类型。 关于ge::DataType的定义，请参见DataType。 |


#### 返回值说明

无。


#### 约束说明

通过该参数设置了Tensor的数据类型，在模型或者图编译后，Tensor的数据类型可能会被刷新。


#### 调用示例

```
StorageShape sh({1, 2, 3}, {1, 2, 3});
Tensor t = {sh, {ge::FORMAT_ND, ge::FORMAT_FRACTAL_NZ, {}}, kOnHost, ge::DT_FLOAT, nullptr};
t.SetDataType(ge::DT_DOUBLE);
```
