create
zarr.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
zarr.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 |
|
zarr.create_array ¶
create_array(
store: StoreLike,
*,
name: str | None = None,
shape: ShapeLike | None = None,
dtype: ZDTypeLike | None = None,
data: ndarray[Any, dtype[Any]] | None = None,
chunks: tuple[int, ...] | Literal["auto"] = "auto",
shards: ShardsLike | None = None,
filters: FiltersLike = "auto",
compressors: CompressorsLike = "auto",
serializer: SerializerLike = "auto",
fill_value: Any | None = DEFAULT_FILL_VALUE,
order: MemoryOrder | None = None,
zarr_format: ZarrFormat | None = 3,
attributes: dict[str, JSON] | None = None,
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
dimension_names: DimensionNames = None,
storage_options: dict[str, Any] | None = None,
overwrite: bool = False,
config: ArrayConfigLike | None = None,
write_data: bool = True,
) -> Array
Create an array.
This function wraps zarr.core.array.create_array.
Parameters:
-
store
(StoreLike
) –Store or path to directory in file system or name of zip file.
-
name
(str or None
, default:None
) –The name of the array within the store. If
name
isNone
, the array will be located at the root of the store. -
shape
(ShapeLike
, default:None
) –Shape of the array. Must be
None
ifdata
is provided. -
dtype
(ZDTypeLike | None
, default:None
) –Data type of the array. Must be
None
ifdata
is provided. -
data
(ndarray
, default:None
) –Array-like data to use for initializing the array. If this parameter is provided, the
shape
anddtype
parameters must beNone
. -
chunks
(tuple[int, ...] | Literal['auto']
, default:"auto"
) –Chunk shape of the array. If chunks is "auto", a chunk shape is guessed based on the shape of the array and the dtype.
-
shards
(tuple[int, ...]
, default:None
) –Shard shape of the array. The default value of
None
results in no sharding at all. -
filters
(Iterable[Codec] | Literal['auto']
, default:'auto'
) –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
. -
compressors
(Iterable[Codec]
, default:'auto'
) –List of compressors to apply to the array. Compressors are applied in order, and after any filters are applied (if any are specified) and the data is serialized into bytes.
For Zarr format 3, a "compressor" is a codec that takes a bytestream, and returns another bytestream. Multiple compressors my be provided for Zarr format 3. If no
compressors
are provided, a default set of compressors will be used. These defaults can be changed by modifying the value ofarray.v3_default_compressors
inzarr.config
. UseNone
to omit default compressors.For Zarr format 2, a "compressor" can be any numcodecs codec. Only a single compressor may be provided for Zarr format 2. If no
compressor
is provided, a default compressor will be used. inzarr.config
. UseNone
to omit the default compressor. -
serializer
(dict[str, JSON] | ArrayBytesCodec
, default:'auto'
) –Array-to-bytes codec to use for encoding the array data. Zarr format 3 only. Zarr format 2 arrays use implicit array-to-bytes conversion. If no
serializer
is provided, a default serializer will be used. These defaults can be changed by modifying the value ofarray.v3_default_serializer
inzarr.config
. -
fill_value
(Any
, default:DEFAULT_FILL_VALUE
) –Fill value for the array.
-
order
(('C', 'F')
, default:"C"
) –The memory of the array (default is "C"). For Zarr format 2, this parameter sets the memory order of the array. For Zarr format 3, this parameter is deprecated, because memory order is a runtime parameter for Zarr format 3 arrays. The recommended way to specify the memory order for Zarr format 3 arrays is via the
config
parameter, e.g.{'config': 'C'}
. If noorder
is provided, a default order will be used. This default can be changed by modifying the value ofarray.order
inzarr.config
. -
zarr_format
((2, 3)
, default:2
) –The zarr format to use when saving.
-
attributes
(dict
, default:None
) –Attributes for the array.
-
chunk_key_encoding
(ChunkKeyEncodingLike
, default:None
) –A specification of how the chunk keys are represented in storage. For Zarr format 3, the default is
{"name": "default", "separator": "/"}}
. For Zarr format 2, the default is{"name": "v2", "separator": "."}}
. -
dimension_names
(Iterable[str]
, default:None
) –The names of the dimensions (default is None). Zarr format 3 only. Zarr format 2 arrays should not use this parameter.
-
storage_options
(dict
, default:None
) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
overwrite
(bool
, default:False
) –Whether to overwrite an array with the same name in the store, if one exists. If
True
, all existing paths in the store will be deleted. -
config
(ArrayConfigLike
, default:None
) –Runtime configuration for the array.
-
write_data
(bool
, default:True
) –If a pre-existing array-like object was provided to this function via the
data
parameter thenwrite_data
determines whether the values in that array-like object should be written to the Zarr array created by this function. Ifwrite_data
isFalse
, then the array will be left empty.
Returns:
-
Array
–The array.
Examples:
>>> import zarr
>>> store = zarr.storage.MemoryStore()
>>> arr = await zarr.create_array(
>>> store=store,
>>> shape=(100,100),
>>> chunks=(10,10),
>>> dtype='i4',
>>> fill_value=0)
<Array memory://140349042942400 shape=(100, 100) dtype=int32>
Source code in zarr/api/synchronous.py
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 |
|
zarr.create_group ¶
create_group(
store: StoreLike,
*,
path: str | None = None,
zarr_format: ZarrFormat | None = None,
overwrite: bool = False,
attributes: dict[str, Any] | None = None,
storage_options: dict[str, Any] | None = None,
) -> Group
Create a group.
Parameters:
-
store
(StoreLike
) –Store or path to directory in file system or name of zip file.
-
path
(str
, default:None
) –Group path within store.
-
overwrite
(bool
, default:False
) –If True, pre-existing data at
path
will be deleted before creating the group. -
zarr_format
((2, 3, None)
, default:2
) –The zarr format to use when saving. If no
zarr_format
is provided, the default format will be used. This default can be changed by modifying the value ofdefault_zarr_format
inzarr.config
. -
storage_options
(dict
, default:None
) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
Returns:
-
Group
–The new group.
Source code in zarr/api/synchronous.py
zarr.create_hierarchy ¶
create_hierarchy(
*,
store: Store,
nodes: dict[
str,
GroupMetadata | ArrayV2Metadata | ArrayV3Metadata,
],
overwrite: bool = False,
) -> Iterator[tuple[str, Group | Array]]
Create a complete zarr hierarchy from a collection of metadata objects.
This function will parse its input to ensure that the hierarchy is complete. Any implicit groups
will be inserted as needed. For example, an input like
{'a/b': GroupMetadata}
will be parsed to
{'': GroupMetadata, 'a': GroupMetadata, 'b': Groupmetadata}
After input parsing, this function then creates all the nodes in the hierarchy concurrently.
Arrays and Groups are yielded in the order they are created. This order is not stable and should not be relied on.
Parameters:
-
store
(Store
) –The storage backend to use.
-
nodes
(dict[str, GroupMetadata | ArrayV3Metadata | ArrayV2Metadata]
) –A dictionary defining the hierarchy. The keys are the paths of the nodes in the hierarchy, relative to the root of the
Store
. The root of the store can be specified with the empty string''
. The values are instances ofGroupMetadata
orArrayMetadata
. Note that all values must have the samezarr_format
-- it is an error to mix zarr versions in the same hierarchy.Leading "/" characters from keys will be removed.
-
overwrite
(bool
, default:False
) –Whether to overwrite existing nodes. Defaults to
False
, in which case an error is raised instead of overwriting an existing array or group.This function will not erase an existing group unless that group is explicitly named in
nodes
. Ifnodes
defines implicit groups, e.g.{`'a/b/c': GroupMetadata}
, and a group already exists at patha
, then this function will leave the group ata
as-is.
Yields:
-
tuple[str, Group | Array]
–This function yields (path, node) pairs, in the order the nodes were created.
Examples:
>>> from zarr import create_hierarchy
>>> from zarr.storage import MemoryStore
>>> from zarr.core.group import GroupMetadata
>>> store = MemoryStore()
>>> nodes = {'a': GroupMetadata(attributes={'name': 'leaf'})}
>>> nodes_created = dict(create_hierarchy(store=store, nodes=nodes))
>>> print(nodes)
# {'a': GroupMetadata(attributes={'name': 'leaf'}, zarr_format=3, consolidated_metadata=None, node_type='group')}
Source code in zarr/core/sync_group.py
zarr.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
zarr.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
zarr.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
zarr.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
zarr.from_array ¶
from_array(
store: StoreLike,
*,
data: Array | ArrayLike,
write_data: bool = True,
name: str | None = None,
chunks: Literal["auto", "keep"]
| tuple[int, ...] = "keep",
shards: ShardsLike | None | Literal["keep"] = "keep",
filters: FiltersLike | Literal["keep"] = "keep",
compressors: CompressorsLike | Literal["keep"] = "keep",
serializer: SerializerLike | Literal["keep"] = "keep",
fill_value: Any | None = DEFAULT_FILL_VALUE,
order: MemoryOrder | None = None,
zarr_format: ZarrFormat | None = None,
attributes: dict[str, JSON] | None = None,
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
dimension_names: DimensionNames = None,
storage_options: dict[str, Any] | None = None,
overwrite: bool = False,
config: ArrayConfigLike | None = None,
) -> Array
Create an array from an existing array or array-like.
Parameters:
-
store
(StoreLike
) –Store or path to directory in file system or name of zip file.
-
data
(Array | array - like
) –The array to copy.
-
write_data
(bool
, default:True
) –Whether to copy the data from the input array to the new array. If
write_data
isFalse
, the new array will be created with the same metadata as the input array, but without any data. -
name
(str or None
, default:None
) –The name of the array within the store. If
name
isNone
, the array will be located at the root of the store. -
chunks
(tuple[int, ...] or 'auto' or 'keep'
, default:'keep'
) –Chunk shape of the array. Following values are supported:
- "auto": Automatically determine the chunk shape based on the array's shape and dtype.
- "keep": Retain the chunk shape of the data array if it is a zarr Array.
- tuple[int, ...]: A tuple of integers representing the chunk shape.
If not specified, defaults to "keep" if data is a zarr Array, otherwise "auto".
-
shards
(tuple[int, ...]
, default:'keep'
) –Shard shape of the array. Following values are supported:
- "auto": Automatically determine the shard shape based on the array's shape and chunk shape.
- "keep": Retain the shard shape of the data array if it is a zarr Array.
- tuple[int, ...]: A tuple of integers representing the shard shape.
- None: No sharding.
If not specified, defaults to "keep" if data is a zarr Array, otherwise None.
-
filters
(Iterable[Codec] | Literal['auto', 'keep']
, default:'keep'
) –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
"keep"
instructs Zarr to inferfilters
fromdata
. If that inference is not possible, Zarr will fall back to the behavior specified by"auto"
, which is to choose default filters 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 the empty tuple()
. 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 is a tuple with 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
. -
compressors
(Iterable[Codec] or 'auto' or 'keep'
, default:'keep'
) –List of compressors to apply to the array. Compressors are applied in order, and after any filters are applied (if any are specified) and the data is serialized into bytes.
For Zarr format 3, a "compressor" is a codec that takes a bytestream, and returns another bytestream. Multiple compressors my be provided for Zarr format 3.
For Zarr format 2, a "compressor" can be any numcodecs codec. Only a single compressor may be provided for Zarr format 2.
Following values are supported:
- Iterable[Codec]: List of compressors to apply to the array.
- "auto": Automatically determine the compressors based on the array's dtype.
- "keep": Retain the compressors of the input array if it is a zarr Array.
If no
compressors
are provided, defaults to "keep" if data is a zarr Array, otherwise "auto". -
serializer
(dict[str, JSON] | ArrayBytesCodec or 'auto' or 'keep'
, default:'keep'
) –Array-to-bytes codec to use for encoding the array data. Zarr format 3 only. Zarr format 2 arrays use implicit array-to-bytes conversion.
Following values are supported:
- dict[str, JSON]: A dict representation of an
ArrayBytesCodec
. - ArrayBytesCodec: An instance of
ArrayBytesCodec
. - "auto": a default serializer will be used. These defaults can be changed by modifying the value of
array.v3_default_serializer
inzarr.config
. - "keep": Retain the serializer of the input array if it is a zarr Array.
- dict[str, JSON]: A dict representation of an
-
fill_value
(Any
, default:DEFAULT_FILL_VALUE
) –Fill value for the array. If not specified, defaults to the fill value of the data array.
-
order
(('C', 'F')
, default:"C"
) –The memory of the array (default is "C"). For Zarr format 2, this parameter sets the memory order of the array. For Zarr format 3, this parameter is deprecated, because memory order is a runtime parameter for Zarr format 3 arrays. The recommended way to specify the memory order for Zarr format 3 arrays is via the
config
parameter, e.g.{'config': 'C'}
. If not specified, defaults to the memory order of the data array. -
zarr_format
((2, 3)
, default:2
) –The zarr format to use when saving. If not specified, defaults to the zarr format of the data array.
-
attributes
(dict
, default:None
) –Attributes for the array. If not specified, defaults to the attributes of the data array.
-
chunk_key_encoding
(ChunkKeyEncoding
, default:None
) –A specification of how the chunk keys are represented in storage. For Zarr format 3, the default is
{"name": "default", "separator": "/"}}
. For Zarr format 2, the default is{"name": "v2", "separator": "."}}
. If not specified and the data array has the same zarr format as the target array, the chunk key encoding of the data array is used. -
dimension_names
(Iterable[str | None] | None
, default:None
) –The names of the dimensions (default is None). Zarr format 3 only. Zarr format 2 arrays should not use this parameter. If not specified, defaults to the dimension names of the data 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.
-
overwrite
(bool
, default:False
) –Whether to overwrite an array with the same name in the store, if one exists.
-
config
(ArrayConfig or ArrayConfigLike
, default:None
) –Runtime configuration for the array.
Returns:
-
Array
–The array.
Examples:
Create an array from an existing Array::
>>> import zarr
>>> store = zarr.storage.MemoryStore()
>>> store2 = zarr.storage.LocalStore('example.zarr')
>>> arr = zarr.create_array(
>>> store=store,
>>> shape=(100,100),
>>> chunks=(10,10),
>>> dtype='int32',
>>> fill_value=0)
>>> arr2 = zarr.from_array(store2, data=arr)
<Array file://example.zarr shape=(100, 100) dtype=int32>
Create an array from an existing NumPy array::
>>> import numpy as np
>>> arr3 = zarr.from_array(
zarr.storage.MemoryStore(),
>>> data=np.arange(10000, dtype='i4').reshape(100, 100),
>>> )
<Array memory://125477403529984 shape=(100, 100) dtype=int32>
Create an array from any array-like object::
>>> arr4 = zarr.from_array(
>>> zarr.storage.MemoryStore(),
>>> data=[[1, 2], [3, 4]],
>>> )
<Array memory://125477392154368 shape=(2, 2) dtype=int64>
>>> arr4[...]
array([[1, 2],[3, 4]])
Create an array from an existing Array without copying the data::
>>> arr5 = zarr.from_array(
>>> zarr.storage.MemoryStore(),
>>> data=arr4,
>>> write_data=False,
>>> )
<Array memory://140678602965568 shape=(2, 2) dtype=int64>
>>> arr5[...]
array([[0, 0],[0, 0]])
Source code in zarr/api/synchronous.py
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 |
|
zarr.group ¶
group(
store: StoreLike | None = None,
*,
overwrite: bool = False,
chunk_store: StoreLike | None = None,
cache_attrs: bool | None = None,
synchronizer: Any | None = None,
path: str | None = None,
zarr_version: ZarrFormat | None = None,
zarr_format: ZarrFormat | None = None,
meta_array: Any | None = None,
attributes: dict[str, JSON] | None = None,
storage_options: dict[str, Any] | None = None,
) -> Group
Create a group.
Parameters:
-
store
(StoreLike or None
, default:None
) –Store or path to directory in file system or name of zip file.
-
overwrite
(bool
, default:False
) –If True, delete any pre-existing data in
store
atpath
before creating the group. -
chunk_store
(StoreLike or None
, default:None
) –Separate storage for chunks. Not implemented.
-
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.
-
synchronizer
(object
, default:None
) –Array synchronizer.
-
path
(str
, default:None
) –Group path within store.
-
meta_array
(array - like
, default:None
) –An array instance to use for determining arrays to create and return to users. Use
numpy.empty(())
by default. -
zarr_format
((2, 3, None)
, default:2
) –The zarr format to use when saving.
-
storage_options
(dict
, default:None
) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
Returns:
-
g
(Group
) –The new group.
Source code in zarr/api/synchronous.py
zarr.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
zarr.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
zarr.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
zarr.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.