> 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/3.13.3.-shape-manipulation.md).

# 3.13.3.     Shape Manipulation

배열은 각 축을 따라 요소들의 수만큼 주어진 모양을 가집니다. 배열의 모양은 다양한 명령으로 변경할 수 있습니다. 다음 세 명령은 모두 수정된 배열을 반환하지만 원래 배열은 변경하지 않습니다.

```python
 import numpy as np

 a = np.floor(10*np.random.random((3,4)))
 print("3행 4열 배열 생성\n", a)
 print("a 배열의 shape = ",a.shape)

 print("a.ravel 결과값\n",a.ravel())  # returns the array, flattened
 print("a.reshape(6,2) 결과값\n",a.reshape(6,2))  # returns the array with a modified shape
 print("a.T 결과값\n",a.T)  # returns the array, transposed
 print("a.T.shape 결과값 = ",a.T.shape)
 print("a.shape 결과값 = ",a.shape)
```

위의 코드를 수행 하면 다음과 같은 결과를 출력합니다.

```
3행 4열 배열 생성
 [[8. 0. 1. 7.]
 [9. 2. 6. 1.]
 [9. 9. 3. 5.]]
a 배열의 shape =  (3, 4)
a.ravel 결과값
 [8. 0. 1. 7. 9. 2. 6. 1. 9. 9. 3. 5.]
a.reshape(6,2) 결과값
 [[8. 0.]
 [1. 7.]
 [9. 2.]
 [6. 1.]
 [9. 9.]
 [3. 5.]]
a.T 결과값
 [[8. 9. 9.]
 [0. 2. 9.]
 [1. 6. 3.]
 [7. 1. 5.]]
a.T.shape 결과값 =  (4, 3)
a.shape 결과값 =  (3, 4)
```

np.random.random은 0 \~ 1 사이의 균등 분포로 표본을 추출합니다. np.floor 함수로 최대 정수로 변환합니다. 따라서 a = np.floor(10\*np.random.random((3,4))) 코드에 의해 3행 4열의 1에서 10사의의 값을 갖는 랜덤 정수 배열이 생성 됩니다.

ravel 함수는 다차원 배열(array)을 1차원 배열로 평평하게 펴주는 함수입니다. 배열의 차원(Dimension)을 재구조화, 변경하고자 할 때 reshape() 메소드를 사용합니다. 가령, 3개의 행과 4개의 열로 구성된 2차원의 배열로 재설정하고 싶으면 reshape(3, 4)처럼 사용하면 됩니다.

T 함수는 각 요소들을 행, 열을 바꾸는 전치(transpose)를 수행합니다.


---

# 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/3.13.3.-shape-manipulation.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.
