title_wip

[Edit this page](https://github.com/ClickHouse/ClickHouse/tree/master/docs/en/interfaces/formats/Npy.md)

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

## Description[​](#description "Direct link to Description")

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:

## Data types matching[​](#data_types-matching "Direct link to Data types matching")

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

## Example usage[​](#example-usage "Direct link to Example usage")

### Saving an array in .npy format using Python[​](#saving-an-array-in-npy-format-using-python "Direct link to Saving an array in .npy format using Python")

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

### Reading a NumPy file in ClickHouse[​](#reading-a-numpy-file-in-clickhouse "Direct link to Reading a NumPy file in ClickHouse")

```
SELECT *
FROM file('example_array.npy', Npy)
```

```
┌─array─────────┐
│ [[1],[2],[3]] │
│ [[4],[5],[6]] │
└───────────────┘
```

### Selecting data[​](#selecting-data "Direct link to Selecting data")

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:

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

## Format settings[​](#format-settings "Direct link to Format settings")

- [Description](#description)- [Data types matching](#data_types-matching)- [Example usage](#example-usage)
      - [Saving an array in .npy format using Python](#saving-an-array-in-npy-format-using-python)- [Reading a NumPy file in ClickHouse](#reading-a-numpy-file-in-clickhouse)- [Selecting data](#selecting-data)- [Format settings](#format-settings)

Was this page helpful?