---
title: operator[]
description: "获取指定idx轴的步长值。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/maintenref/basicdataapi/atlasopapi_07_00726.html
sourcePath: /source/zh/canncommercial/900/maintenref/basicdataapi/atlasopapi_07_00726.html
indexId: d891329eedbdcf566a212bb51cfc6dc6d8197d8d2b7a9a9a439d28e6340d55d378
---
# operator[]

#### 函数功能

获取指定idx轴的步长值。


#### 函数原型

```
const int64_t &operator[](const size_t idx) const
int64_t &operator[](const size_t idx)
```


#### 参数说明

| 参数 | 输入/输出 | 说明 |
| --- | --- | --- |
| idx | 输入 | 维度的索引，调用者需要保证索引合法。 |


#### 返回值说明

- const int64_t &operator[](const size_t idx) const：步长值，在idx>=kMaxDimNum时，行为未定义。
- int64_t &operator[](const size_t idx)：dim值，在idx>=kMaxDimNum时，行为未定义。


#### 约束说明

调用者需要保证index合法，即idx<kMaxDimNum。


#### 调用示例

```
Stride stride({3, 256, 256});
auto str0 = stride[0]; // 3
auto str5 = stride[5]; // 0
auto invalid_str = stride[Stride::kMaxDimNum]; // 行为未定义
```
