> For the complete documentation index, see [llms.txt](https://sdc-james.gitbook.io/onebook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sdc-james.gitbook.io/onebook/4.-numpy-and-scipy/4.1-numpy/4.1.2.-indexing-slicing-iterating.md).

# 4.1.2.     Indexing, Slicing 그리고 Iterating

1 차원 배열은 리스트 및 기타 파이썬 시퀀스와 마찬가지로 색인 생성, 슬라이스 및 반복 될 수 있습니다. 다차원 배열은 축 당 하나의 인덱스를 가질 수 있습니다. 이러한 인덱스는 쉼표로 구분된 튜플로 제공됩니다.

```python
import numpy as np

 a = np.arange(10)**3
 print("1부터 10까지 3자승 한 배열 a =",a)
 print("a 배열의 두번째 인덱스 값 = ", a[2])
 print("a 배열의 2:5 인덱스 값 = ", a[2:5])
 a[0:6:2] = -1000    # from start to position 6, exclusive, set every 2nd element to -1000
 print("a 배열의 0번째 부터 6번째 까지 모든 두번째 값에 -1000을 대입한 값 = ", a)
 print("a 배열을 뒤집은 값  = ", a[ : :-1])          # reversed a

 #각 행마다 10씩 증가하는 배열 생성
 def f(x,y):
      return 10*x+y

 ab = np.fromfunction(f,(5,4),dtype=int)
 print("각 행마다 10씩 증가하는 배열 생성\n",ab)
 print("생성된 배열의 2행 3열 값 = ",ab[2,3])
 print("생성된 배열 각행 2열 값 = ",ab[0:5, 1])
 print("생성된 배열 각행 1행~2행 값 \n ",ab[1:3, : ])
```

위 코드를 실행하면 다음과 같은 결과가 출력 됩니다.

```
1부터 10까지 3자승 한 배열 a = [  0   1   8  27  64 125 216 343 512 729]
a 배열의 두번째 인덱스 값 =  8
a 배열의 2:5 인덱스 값 =  [ 8 27 64]
a 배열의 0번째 부터 6번째 까지 모든 두번째 값에 -1000을 대입한 값 =  [-1000     1 -1000    27 -1000   125   216   343   512   729]
a 배열을 뒤집은 값  =  [  729   512   343   216   125 -1000    27 -1000     1 -1000]
각 행마다 10씩 증가하는 배열 생성
 [[ 0  1  2  3]
 [10 11 12 13]
 [20 21 22 23]
 [30 31 32 33]
 [40 41 42 43]]
생성된 배열의 2행 3열 값 =  23
생성된 배열 각행 2열 값 =  [ 1 11 21 31 41]
생성된 배열 각행 1행~2행 값
  [[10 11 12 13]
 [20 21 22 23]]
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sdc-james.gitbook.io/onebook/4.-numpy-and-scipy/4.1-numpy/4.1.2.-indexing-slicing-iterating.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
