Search Shortcut cmd + k | ctrl + k
Search cmd+k ctrl+k
1.0 (stable)
Export to Numpy

The result of a query can be converted to a Numpy array using the fetchnumpy() function. For example:

import duckdb
import numpy as np

my_arr = duckdb.sql("SELECT unnest([1, 2, 3]) AS x, 5.0 AS y").fetchnumpy()
{'x': array([1, 2, 3], dtype=int32), 'y': masked_array(data=[5.0, 5.0, 5.0],
             mask=[False, False, False],

Then, the array can be processed using Numpy functions, e.g.:


See Also

DuckDB also supports importing from Numpy.

About this page

Last modified: 2024-06-12