> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8c05c8a2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Npy 포맷 문서

# Npy

| 입력 | 출력 | 별칭 |
| -- | -- | -- |
| ✔  | ✔  |    |

<div id="description">
  ## 설명
</div>

`Npy` 포맷은 `.npy` 파일의 NumPy 배열을 ClickHouse로 로드할 수 있도록 설계되었습니다.
NumPy 파일 포맷은 수치 데이터 배열을 효율적으로 저장하는 데 사용되는 바이너리 형식입니다.
가져오는 과정에서 ClickHouse는 최상위 차원을 단일 컬럼으로 이루어진 행 배열로 처리합니다.

아래 표에는 지원되는 Npy 데이터 타입과 ClickHouse에서의 대응 타입이 나와 있습니다:

<div id="data_types-matching">
  ## 데이터 타입 매핑
</div>

| Npy 데이터 타입 (`INSERT`) | ClickHouse 데이터 타입                                   | Npy 데이터 타입 (`SELECT`) |
| --------------------- | --------------------------------------------------- | --------------------- |
| `i1`                  | [Int8](/ko/reference/data-types/int-uint)           | `i1`                  |
| `i2`                  | [Int16](/ko/reference/data-types/int-uint)          | `i2`                  |
| `i4`                  | [Int32](/ko/reference/data-types/int-uint)          | `i4`                  |
| `i8`                  | [Int64](/ko/reference/data-types/int-uint)          | `i8`                  |
| `u1`, `b1`            | [UInt8](/ko/reference/data-types/int-uint)          | `u1`                  |
| `u2`                  | [UInt16](/ko/reference/data-types/int-uint)         | `u2`                  |
| `u4`                  | [UInt32](/ko/reference/data-types/int-uint)         | `u4`                  |
| `u8`                  | [UInt64](/ko/reference/data-types/int-uint)         | `u8`                  |
| `f2`, `f4`            | [Float32](/ko/reference/data-types/float)           | `f4`                  |
| `f8`                  | [Float64](/ko/reference/data-types/float)           | `f8`                  |
| `S`, `U`              | [String](/ko/reference/data-types/string)           | `S`                   |
|                       | [FixedString](/ko/reference/data-types/fixedstring) | `S`                   |

<div id="example-usage">
  ## 사용 예시
</div>

<div id="saving-an-array-in-npy-format-using-python">
  ### Python을 사용해 배열을 .npy 포맷으로 저장하기
</div>

```Python theme={null}
import numpy as np
arr = np.array([[[1],[2],[3]],[[4],[5],[6]]])
np.save('example_array.npy', arr)
```

<div id="reading-a-numpy-file-in-clickhouse">
  ### ClickHouse에서 NumPy 파일 읽기
</div>

```sql title="Query" theme={null}
SELECT *
FROM file('example_array.npy', Npy)
```

```response title="Response" theme={null}
┌─array─────────┐
│ [[1],[2],[3]] │
│ [[4],[5],[6]] │
└───────────────┘
```

<div id="selecting-data">
  ### 데이터 선택
</div>

다음과 같이 `clickhouse-client` 명령을 사용하면 ClickHouse 테이블에서 데이터를 선택해 Npy 포맷의 파일에 저장할 수 있습니다:

```bash theme={null}
$ clickhouse-client --query="SELECT {column} FROM {some_table} FORMAT Npy" > {filename.npy}
```

<div id="format-settings">
  ## 포맷 설정
</div>
