Skip to content

 zarr.ones_like

zarr.ones_like

ones_like(
    a: ArrayLike,
    *,
    zarr_format: ZarrFormat | None = None,
    **kwargs: Any,
) -> AnyArray

Create an array of ones like another array.

Parameters:

  • a (array - like) –

    The array to create an empty array like.

  • zarr_format ((2, 3, None), default: 2 ) –

    The zarr format of the new array. If None (default), the zarr format of a if it is a zarr array, otherwise the default zarr format.

  • **kwargs (Any, default: {} ) –

    Keyword arguments passed to zarr.api.asynchronous.create.

Returns:

  • Array –

    The new array.

Source code in src/zarr/api/synchronous.py
def ones_like(a: ArrayLike, *, zarr_format: ZarrFormat | None = None, **kwargs: Any) -> AnyArray:
    """Create an array of ones like another array.

    Parameters
    ----------
    a : array-like
        The array to create an empty array like.
    zarr_format : {2, 3, None}, optional
        The zarr format of the new array. If `None` (default), the zarr format of `a` if it
        is a zarr array, otherwise the default zarr format.
    **kwargs
        Keyword arguments passed to [`zarr.api.asynchronous.create`][].

    Returns
    -------
    Array
        The new array.
    """
    return Array(sync(async_api.ones_like(a, zarr_format=zarr_format, **kwargs)))