runlmc.util.numpy_convenience module

Convenience functions for working with numpy arrays.

runlmc.util.numpy_convenience.begin_end_indices(lens)[source]
runlmc.util.numpy_convenience.cartesian_product(*arrays)[source]
runlmc.util.numpy_convenience.chunks(l, n)[source]

Yield successive n-sized chunks from l.

runlmc.util.numpy_convenience.map_entries(f, nparr)[source]

Map a function over a numpy array.

Parameters:
  • f – single-parameter function over the same types
  • nparr (np.ndarray) – arbitrary numpy array
Returns:

A numpy array with f evaluated on each element of the same shape.

runlmc.util.numpy_convenience.search_descending(x, xs, inclusive)[source]
Parameters:
  • x – threshold
  • xs – descending-ordered array to search
  • inclusive – whether to include values of x in xs
Returns:

the largest index index i such that xs[:i] >= x if inclusive else xs[:i] > x.

Raises:

ValueError – if array is not weakly decreasing

runlmc.util.numpy_convenience.smallest_eig(top)[source]
Parameters:top – top row of Toeplitz matrix to get eigenvalues for
Returns:the smallest eigenvalue
runlmc.util.numpy_convenience.symm_2d_list_map(f, arr, D, *args, dtype='object')[source]

Symmetric map construction

runlmc.util.numpy_convenience.tesselate(nparr, lenit)[source]

Create a ragged array by splitting nparr into contiguous segments of size determined by the length list lenit

Parameters:
  • nparr – array to split along axis 0.
  • lenit – iterator of lengths to split into.
Returns:

A list of size equal to lenit’s iteration with nparr’s segments split into corresponding size chunks.

Raises:

ValueError – if the sum of lengths doesn’t correspond to the array size.