CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-zarr

An implementation of chunked, compressed, N-dimensional arrays for Python

Overview
Eval results
Files

array-creation.mddocs/

Array Creation and Initialization

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.

Capabilities

Creating Arrays from Data

def array(data: ArrayLike, **kwargs) -> Array

Create 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
) -> Array

Create a zarr array from an existing array. Similar to array() but with different parameter semantics.

Creating Empty Arrays

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
) -> Array

Create a new zarr array with specified shape and properties.

Parameters:

  • shape: Shape of the array as tuple of integers
  • chunks: Chunk shape. If None, uses auto-chunking
  • dtype: Data type (default: 'float64')
  • compressor: Compression codec ('default' uses configured default)
  • fill_value: Fill value for uninitialized elements
  • order: Memory layout ('C' for row-major, 'F' for column-major)
def empty(shape: tuple[int, ...], **kwargs) -> Array

Create 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
) -> Array

Create a new array in a specific store with fine-grained control over storage parameters.

Creating Initialized Arrays

def zeros(shape: tuple[int, ...], **kwargs) -> Array

Create an array filled with zeros.

def ones(shape: tuple[int, ...], **kwargs) -> Array

Create an array filled with ones.

def full(shape: tuple[int, ...], fill_value: Any, **kwargs) -> Array

Create an array filled with a specified value.

Parameters:

  • shape: Shape of the array
  • fill_value: Value to fill the array with
  • dtype: Data type (inferred from fill_value if None)

Creating Arrays Like Existing Arrays

def empty_like(a: ArrayLike, **kwargs) -> Array

Create an uninitialized array with the same shape and properties as an existing array.

def zeros_like(a: ArrayLike, **kwargs) -> Array

Create a zeros array with the same shape and properties as an existing array.

def ones_like(a: ArrayLike, **kwargs) -> Array

Create a ones array with the same shape and properties as an existing array.

def full_like(a: ArrayLike, fill_value: Any, **kwargs) -> Array

Create an array filled with a specified value, using the same shape and properties as an existing array.

Type Definitions

ArrayLike = Union[np.ndarray, Array, list, tuple]
StoreLike = Union[str, os.PathLike, Store, MutableMapping]
CompressorLike = Union[str, dict, Codec]
MemoryOrder = Literal['C', 'F']

Usage Examples

Basic Array Creation

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))

Advanced Creation with Compression

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

docs

array-creation.md

codecs.md

configuration.md

core-classes.md

data-access.md

data-io.md

group-management.md

index.md

storage-backends.md

tile.json