bundles / numpy 2.4.4 / numpy / lib / Arrayterator
class
numpy.lib:Arrayterator
source: /numpy/lib/__init__.py :16
Signature
class Arrayterator ( var , buf_size = None ) Summary
Buffered iterator for big arrays.
Extended Summary
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.
Parameters
var: array_likeThe object to iterate over.
buf_size: int, optionalThe buffer size. If
buf_sizeis supplied, the maximum amount of data that will be read into memory isbuf_sizeelements. Default is None, which will read as many element as possible into memory.
Attributes
varbuf_sizestartstopstepshapeflat
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 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.
Examples
import numpy as np a = np.arange(3 * 4 * 5 * 6).reshape(3, 4, 5, 6) a_itor = np.lib.Arrayterator(a, 2) a_itor.shape✓
See also
- numpy.flatiter
Flat array iterator.
- numpy.memmap
Create a memory-map to an array stored in a binary file on disk.
- numpy.ndenumerate
Multidimensional array iterator.
Aliases
-
numpy.lib.Arrayterator