The result of a query can be converted to Numpy arrays using the fetchnumpy() function, which returns a dictionary that maps each column name to a Numpy array. For example:
import duckdb
import numpy as np
my_arr = duckdb.sql("SELECT unnest([1, 2, 3]) AS x, 5.0 AS y").fetchnumpy()
my_arr
{'x': array([1, 2, 3], dtype=int32), 'y': array([5., 5., 5.])}
Then, the array can be processed using Numpy functions, e.g.:
np.sum(my_arr['x'])
np.int64(6)
See Also
DuckDB also supports importing from Numpy.
© 2026 DuckDB Foundation, Amsterdam NL