Reference

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.

evaluate(simplify=False)[source]

Return the lazy array as a real NumPy array.

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

apply(f)[source]

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.]])
property is_homogeneous

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

property ncols

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

property nrows

Size of the first dimension of the array.

property shape

Shape of the array