An implementation of chunked, compressed, N-dimensional arrays for Python
Functions for creating zarr arrays with various initialization patterns. These provide the primary entry points for creating new arrays with different fill patterns and from existing data sources.
def array(data: ArrayLike, **kwargs) -> ArrayCreate a zarr array from existing array-like data (numpy arrays, lists, etc.).
Parameters:
data: Array-like data to convert to zarr array (numpy arrays, lists, etc.)**kwargs: Additional keyword arguments passed through to create()def from_array(
store: StoreLike,
*,
data: ArrayLike,
write_data: bool = True,
chunks: Literal["auto", "keep"] | tuple[int, ...] = "keep",
fill_value: Any = None,
order: MemoryOrder = None,
zarr_format: int = None,
overwrite: bool = False,
**kwargs
) -> ArrayCreate a zarr array from an existing array. Similar to array() but with different parameter semantics.
def create(
shape: tuple[int, ...] | int,
*,
chunks: tuple[int, ...] | int | bool = None,
dtype: str | np.dtype = None,
compressor: CompressorLike = "auto",
fill_value: Any = None,
order: MemoryOrder = None,
store: StoreLike = None,
overwrite: bool = False,
path: str = None,
zarr_format: int = None,
**kwargs
) -> ArrayCreate a new zarr array with specified shape and properties.
Parameters:
shape: Shape of the array as tuple of integerschunks: Chunk shape. If None, uses auto-chunkingdtype: Data type (default: 'float64')compressor: Compression codec ('default' uses configured default)fill_value: Fill value for uninitialized elementsorder: Memory layout ('C' for row-major, 'F' for column-major)def empty(shape: tuple[int, ...], **kwargs) -> ArrayCreate an uninitialized array (contents are undefined).
def create_array(
store: StoreLike,
*,
name: str = None,
shape: tuple[int, ...] = None,
dtype: str | np.dtype = None,
data: np.ndarray = None,
chunks: tuple[int, ...] | Literal[\"auto\"] = \"auto\",
fill_value: Any = None,
zarr_format: int = 3,
overwrite: bool = False,
**kwargs
) -> ArrayCreate a new array in a specific store with fine-grained control over storage parameters.
def zeros(shape: tuple[int, ...], **kwargs) -> ArrayCreate an array filled with zeros.
def ones(shape: tuple[int, ...], **kwargs) -> ArrayCreate an array filled with ones.
def full(shape: tuple[int, ...], fill_value: Any, **kwargs) -> ArrayCreate an array filled with a specified value.
Parameters:
shape: Shape of the arrayfill_value: Value to fill the array withdtype: Data type (inferred from fill_value if None)def empty_like(a: ArrayLike, **kwargs) -> ArrayCreate an uninitialized array with the same shape and properties as an existing array.
def zeros_like(a: ArrayLike, **kwargs) -> ArrayCreate a zeros array with the same shape and properties as an existing array.
def ones_like(a: ArrayLike, **kwargs) -> ArrayCreate a ones array with the same shape and properties as an existing array.
def full_like(a: ArrayLike, fill_value: Any, **kwargs) -> ArrayCreate an array filled with a specified value, using the same shape and properties as an existing array.
ArrayLike = Union[np.ndarray, Array, list, tuple]
StoreLike = Union[str, os.PathLike, Store, MutableMapping]
CompressorLike = Union[str, dict, Codec]
MemoryOrder = Literal['C', 'F']import zarr
import numpy as np
# Create from numpy array
np_data = np.random.random((100, 100))
z1 = zarr.array(np_data, chunks=(50, 50))
# Create new array with specific initialization
z2 = zarr.zeros((1000, 1000), chunks=(100, 100), dtype='float32')
z3 = zarr.ones((500, 500), chunks=(100, 100))
z4 = zarr.full((200, 200), fill_value=3.14, chunks=(50, 50))from zarr.codecs import BloscCodec
# Create with compression
z = zarr.create(
shape=(10000, 10000),
chunks=(1000, 1000),
dtype='float64',
compressor=BloscCodec(cname='zstd', clevel=3)
)
# Create with multiple filters
from zarr.codecs import BytesCodec
z = zarr.create(
shape=(5000, 5000),
chunks=(500, 500),
codecs=[
BloscCodec(cname='lz4', clevel=1),
BytesCodec()
]
)Install with Tessl CLI
npx tessl i tessl/pypi-zarr