Creation sub-module
zarr.creation ¶
Helpers for creating arrays.
Deprecated
This sub-module is deprecated. All functions here are defined in the top level zarr namespace instead.
array ¶
Create an array filled with data
.
Parameters:
-
data
(array_like
) –The data to fill the array with.
-
**kwargs
(Any
, default:{}
) –Passed through to
create
.
Returns:
-
array
(Array
) –The new array.
Source code in zarr/api/synchronous.py
create ¶
create(
shape: tuple[int, ...] | int,
*,
chunks: tuple[int, ...] | int | bool | None = None,
dtype: ZDTypeLike | None = None,
compressor: CompressorLike = "auto",
fill_value: Any | None = DEFAULT_FILL_VALUE,
order: MemoryOrder | None = None,
store: StoreLike | None = None,
synchronizer: Any | None = None,
overwrite: bool = False,
path: PathLike | None = None,
chunk_store: StoreLike | None = None,
filters: Iterable[dict[str, JSON] | Numcodec]
| None = None,
cache_metadata: bool | None = None,
cache_attrs: bool | None = None,
read_only: bool | None = None,
object_codec: Codec | None = None,
dimension_separator: Literal[".", "/"] | None = None,
write_empty_chunks: bool | None = None,
zarr_version: ZarrFormat | None = None,
zarr_format: ZarrFormat | None = None,
meta_array: Any | None = None,
attributes: dict[str, JSON] | None = None,
chunk_shape: tuple[int, ...] | int | None = None,
chunk_key_encoding: ChunkKeyEncoding
| tuple[Literal["default"], Literal[".", "/"]]
| tuple[Literal["v2"], Literal[".", "/"]]
| None = None,
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
dimension_names: DimensionNames = None,
storage_options: dict[str, Any] | None = None,
config: ArrayConfigLike | None = None,
**kwargs: Any,
) -> Array
Create an array.
Parameters:
-
shape
(int or tuple of ints
) –Array shape.
-
chunks
(int or tuple of ints
, default:None
) –Chunk shape. If True, will be guessed from
shape
anddtype
. If False, will be set toshape
, i.e., single chunk for the whole array. If an int, the chunk size in each dimension will be given by the value ofchunks
. Default is True. -
dtype
(str or dtype
, default:None
) –NumPy dtype.
-
compressor
(Codec
, default:'auto'
) –Primary compressor to compress chunk data. Zarr format 2 only. Zarr format 3 arrays should use
codecs
instead.If neither
compressor
norfilters
are provided, the default compressorzarr.codecs.ZstdCodec
is used.If
compressor
is set toNone
, no compression is used. -
fill_value
(Any
, default:DEFAULT_FILL_VALUE
) –Fill value for the array.
-
order
(('C', 'F')
, default:'C'
) –Deprecated in favor of the
config
keyword argument. Pass{'order': <value>}
tocreate
instead of using this parameter. Memory layout to be used within each chunk. If not specified, thearray.order
parameter in the global config will be used. -
store
(StoreLike or None
, default:None
) –Store or path to directory in file system or name of zip file.
-
synchronizer
(object
, default:None
) –Array synchronizer.
-
overwrite
(bool
, default:False
) –If True, delete all pre-existing data in
store
atpath
before creating the array. -
path
(str
, default:None
) –Path under which array is stored.
-
chunk_store
(StoreLike or None
, default:None
) –Separate storage for chunks. If not provided,
store
will be used for storage of both chunks and metadata. -
filters
(Iterable[Codec] | Literal['auto']
, default:None
) –Iterable of filters to apply to each chunk of the array, in order, before serializing that chunk to bytes.
For Zarr format 3, a "filter" is a codec that takes an array and returns an array, and these values must be instances of
zarr.abc.codec.ArrayArrayCodec
, or a dict representations ofzarr.abc.codec.ArrayArrayCodec
.For Zarr format 2, a "filter" can be any numcodecs codec; you should ensure that the the order if your filters is consistent with the behavior of each filter.
The default value of
"auto"
instructs Zarr to use a default used based on the data type of the array and the Zarr format specified. For all data types in Zarr V3, and most data types in Zarr V2, the default filters are empty. The only cases where default filters are not empty is when the Zarr format is 2, and the data type is a variable-length data type likezarr.dtype.VariableLengthUTF8
orzarr.dtype.VariableLengthUTF8
. In these cases, the default filters contains a single element which is a codec specific to that particular data type.To create an array with no filters, provide an empty iterable or the value
None
. -
cache_metadata
(bool
, default:None
) –If True, array configuration metadata will be cached for the lifetime of the object. If False, array metadata will be reloaded prior to all data access and modification operations (may incur overhead depending on storage and data access pattern).
-
cache_attrs
(bool
, default:None
) –If True (default), user attributes will be cached for attribute read operations. If False, user attributes are reloaded from the store prior to all attribute read operations.
-
read_only
(bool
, default:None
) –True if array should be protected against modification.
-
object_codec
(Codec
, default:None
) –A codec to encode object arrays, only needed if dtype=object.
-
dimension_separator
(('.', '/')
, default:'.'
) –Separator placed between the dimensions of a chunk. Zarr format 2 only. Zarr format 3 arrays should use
chunk_key_encoding
instead. -
write_empty_chunks
(bool
, default:None
) –Deprecated in favor of the
config
keyword argument. Pass{'write_empty_chunks': <value>}
tocreate
instead of using this parameter. If True, all chunks will be stored regardless of their contents. If False, each chunk is compared to the array's fill value prior to storing. If a chunk is uniformly equal to the fill value, then that chunk is not be stored, and the store entry for that chunk's key is deleted. -
zarr_format
((2, 3, None)
, default:2
) –The Zarr format to use when creating an array. The default is
None
, which instructs Zarr to choose the default Zarr format value defined in the runtime configuration. -
meta_array
(array - like
, default:None
) –Not implemented.
-
attributes
(dict[str, JSON]
, default:None
) –A dictionary of user attributes to store with the array.
-
chunk_shape
(int or tuple of ints
, default:None
) –The shape of the Array's chunks (default is None). Zarr format 3 only. Zarr format 2 arrays should use
chunks
instead. -
chunk_key_encoding
(ChunkKeyEncoding
, default:None
) –A specification of how the chunk keys are represented in storage. Zarr format 3 only. Zarr format 2 arrays should use
dimension_separator
instead. Default is("default", "/")
. -
codecs
(Sequence of Codecs or dicts
, default:None
) –An iterable of Codec or dict serializations of Codecs. Zarr V3 only.
The elements of
codecs
specify the transformation from array values to stored bytes. Zarr format 3 only. Zarr format 2 arrays should usefilters
andcompressor
instead.If no codecs are provided, default codecs will be used based on the data type of the array. For most data types, the default codecs are the tuple
(BytesCodec(), ZstdCodec())
; data types that require a specialzarr.abc.codec.ArrayBytesCodec
, like variable-length strings or bytes, will use thezarr.abc.codec.ArrayBytesCodec
required for the data type instead ofzarr.codecs.BytesCodec
. -
dimension_names
(Iterable[str | None] | None = None
, default:None
) –An iterable of dimension names. Zarr format 3 only.
-
storage_options
(dict
, default:None
) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
config
(ArrayConfigLike
, default:None
) –Runtime configuration of the array. If provided, will override the default values from
zarr.config.array
.
Returns:
-
z
(Array
) –The array.
Source code in zarr/api/synchronous.py
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 |
|
empty ¶
Create an empty array with the specified shape. The contents will be filled with the array's fill value or zeros if no fill value is provided.
Parameters:
-
shape
(int or tuple of int
) –Shape of the empty array.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to
create
.
Returns:
-
Array
–The new array.
Notes
The contents of an empty Zarr array are not defined. On attempting to retrieve data from an empty Zarr array, any values may be returned, and these are not guaranteed to be stable from one access to the next.
Source code in zarr/api/synchronous.py
empty_like ¶
Create an empty array like another array. The contents will be filled with the array's fill value or zeros if no fill value is provided.
Parameters:
-
a
(array - like
) –The array to create an empty array like.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to
create
.
Returns:
-
Array
–The new array.
Notes
The contents of an empty Zarr array are not defined. On attempting to retrieve data from an empty Zarr array, any values may be returned, and these are not guaranteed to be stable from one access to the next.
Source code in zarr/api/synchronous.py
full ¶
Create an array with a default fill value.
Parameters:
-
shape
(int or tuple of int
) –Shape of the empty array.
-
fill_value
(scalar
) –Fill value.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to
create
.
Returns:
-
Array
–The new array.
Source code in zarr/api/synchronous.py
full_like ¶
Create a filled array like another array.
Parameters:
-
a
(array - like
) –The array to create an empty array like.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to
zarr.api.asynchronous.create
.
Returns:
-
Array
–The new array.
Source code in zarr/api/synchronous.py
ones ¶
Create an array with a fill value of one.
Parameters:
-
shape
(int or tuple of int
) –Shape of the empty array.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to
zarr.api.asynchronous.create
.
Returns:
-
Array
–The new array.
Source code in zarr/api/synchronous.py
ones_like ¶
Create an array of ones like another array.
Parameters:
-
a
(array - like
) –The array to create an empty array like.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to
zarr.api.asynchronous.create
.
Returns:
-
Array
–The new array.
Source code in zarr/api/synchronous.py
open_array ¶
open_array(
store: StoreLike | None = None,
*,
zarr_version: ZarrFormat | None = None,
zarr_format: ZarrFormat | None = None,
path: PathLike = "",
storage_options: dict[str, Any] | None = None,
**kwargs: Any,
) -> Array
Open an array using file-mode-like semantics.
Parameters:
-
store
(StoreLike
, default:None
) –Store or path to directory in file system or name of zip file.
-
zarr_version
((2, 3, None)
, default:2
) –The zarr format to use when saving. Deprecated in favor of zarr_format.
-
zarr_format
((2, 3, None)
, default:2
) –The zarr format to use when saving.
-
path
(str
, default:''
) –Path in store to array.
-
storage_options
(dict
, default:None
) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
**kwargs
(Any
, default:{}
) –Any keyword arguments to pass to
create
.
Returns:
-
AsyncArray
–The opened array.
Source code in zarr/api/synchronous.py
open_like ¶
Open a persistent array like another array.
Parameters:
-
a
(Array
) –The shape and data-type of a define these same attributes of the returned array.
-
path
(str
) –The path to the new array.
-
**kwargs
(Any
, default:{}
) –Any keyword arguments to pass to the array constructor.
Returns:
-
AsyncArray
–The opened array.
Source code in zarr/api/synchronous.py
zeros ¶
Create an array with a fill value of zero.
Parameters:
-
shape
(int or tuple of int
) –Shape of the empty array.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to
zarr.api.asynchronous.create
.
Returns:
-
Array
–The new array.
Source code in zarr/api/synchronous.py
zeros_like ¶
Create an array of zeros like another array.
Parameters:
-
a
(array - like
) –The array to create an empty array like.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to
create
.
Returns:
-
Array
–The new array.