numpy 1.22.4 Pypi GitHub Homepage
Other Docs
AttributesNotesParametersBackRef

Attributes

var :
buf_size :
start :
stop :
step :
shape :
flat :

Arrayterator creates a buffered iterator for reading big arrays in small contiguous blocks. The class is useful for objects stored in the file system. It allows iteration over the object without reading everything in memory; instead, small blocks are read and iterated over.

Arrayterator can be used with any object that supports multidimensional slices. This includes NumPy arrays, but also variables from Scientific.IO.NetCDF or pynetcdf for example.

Notes

The algorithm works by first finding a "running dimension", along which the blocks will be extracted. Given an array of dimensions (d1, d2, ..., dn) , e.g. if :None:None:`buf_size` is smaller than d1 , the first dimension will be used. If, on the other hand, d1 < buf_size < d1*d2 the second dimension will be used, and so on. Blocks are extracted along this dimension, and when the last block is returned the process continues from the next dimension, until all elements have been read.

Parameters

var : array_like

The object to iterate over.

buf_size : int, optional

The buffer size. If :None:None:`buf_size` is supplied, the maximum amount of data that will be read into memory is :None:None:`buf_size` elements. Default is None, which will read as many element as possible into memory.

Buffered iterator for big arrays.

See Also

flatiter

Flat array iterator.

memmap

Create a memory-map to an array stored in a binary file on disk.

ndenumerate

Multidimensional array iterator.

Examples

>>> a = np.arange(3 * 4 * 5 * 6).reshape(3, 4, 5, 6)
... a_itor = np.lib.Arrayterator(a, 2)
... a_itor.shape (3, 4, 5, 6)

Now we can iterate over a_itor , and it will return arrays of size two. Since :None:None:`buf_size` was smaller than any dimension, the first dimension will be iterated over first:

>>> for subarr in a_itor:
...  if not subarr.all():
...  print(subarr, subarr.shape) # doctest: +SKIP
... # [[[[0 1]]]] (1, 1, 1, 2)
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

numpy.lib.arrayterator numpy.lib.arrayterator.Arrayterator

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/lib/arrayterator.py#16
type: <class 'type'>
Commit: