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

> Documentation for the Npy format

# Npy

| Input | Output | Alias |
| ----- | ------ | ----- |
| ✔     | ✔      |       |

<h2 id="description">
  Description
</h2>

The `Npy` format is designed to load a NumPy array from a `.npy` file into ClickHouse.
The NumPy file format is a binary format used for efficiently storing arrays of numerical data.
During import, ClickHouse treats the top level dimension as an array of rows with a single column.

The table below gives the supported Npy data types and their corresponding type in ClickHouse:

<h2 id="data_types-matching">
  Data types matching
</h2>

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

<h2 id="example-usage">
  Example usage
</h2>

<h3 id="saving-an-array-in-npy-format-using-python">
  Saving an array in .npy format using Python
</h3>

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

<h3 id="reading-a-numpy-file-in-clickhouse">
  Reading a NumPy file in ClickHouse
</h3>

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

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

<h3 id="selecting-data">
  Selecting data
</h3>

You can select data from a ClickHouse table and save it into a file in the Npy format using the following command with clickhouse-client:

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

<h2 id="format-settings">
  Format settings
</h2>
