polars.Series.to_numpy

Series.to_numpy(*args: Any, zero_copy_only: bool = False, **kwargs: Any) numpy.ndarray

Convert this Series to numpy. This operation clones data but is completely safe.

If you want a zero-copy view and know what you are doing, use .view().

Parameters
args

args will be sent to pyarrow.Array.to_numpy.

zero_copy_only

If True, an exception will be raised if the conversion to a numpy array would require copying the underlying data (e.g. in presence of nulls, or for non-primitive types).

kwargs

kwargs will be sent to pyarrow.Array.to_numpy

Notes

If you are attempting to convert Utf8 to an array you’ll need to install pyarrow.

Examples

>>> s = pl.Series("a", [1, 2, 3])
>>> arr = s.to_numpy()
>>> arr  
array([1, 2, 3], dtype=int64)
>>> type(arr)
<class 'numpy.ndarray'>