class lazyarray.larray(value, shape=None, dtype=None)[source]
Optimises storage of and operations on arrays in various ways:
  • stores only a single value if all the values in the array are the same;
  • if the array is created from a function f(i) or f(i,j), then elements are only evaluated when they are accessed. Any operations performed on the array are also queued up to be executed on access.
Two use cases for the latter are:
  • to save memory for very large arrays by accessing them one row or column at a time: the entire array need never be in memory.
  • in parallelized code, different rows or columns may be evaluated on different nodes or in different threads.

Return the lazy array as a real NumPy array.

If the array is homogeneous and simplify is True, return a single numerical value.


Add the function f(x) to the list of the operations to be performed, where x will be a scalar or a numpy array.

>>> m = larray(4, shape=(2,2))
>>> m.apply(numpy.sqrt)
>>> m.evaluate()
array([[ 2.,  2.],
       [ 2.,  2.]])

True if all the elements of the array are the same.


Size of the second dimension (if it exists) of the array.


Size of the first dimension of the array.


Shape of the array

Previous topic


Next topic

Developers’ guide

This Page