schlichtanders.mynumpy module

Addition to myarrays. They should merged I think.

schlichtanders.mynumpy.array(gen)[source]
schlichtanders.mynumpy.complex_reshape(flat, shapes)[source]

reshapes flat into elements with shapes

Parameters:
  • flat (list) – shall be reshaped
  • shapes (list of tuples (shapes)) – will reshape list consecutively into summarizing elements with given shape
Returns:

Return type:

list of reshapes

schlichtanders.mynumpy.deepflatten(maybe_iterable)[source]
schlichtanders.mynumpy.find(a, predicate, chunk_size=1024)[source]

Find the indices of array elements that match the predicate.

Parameters:
  • a (array_like) – Input data, must be 1D.
  • predicate (function) – A function which operates on sections of the given array, returning element-wise True or False for each data value.
  • chunk_size (integer) – The length of the chunks to use when searching for matching indices. For high probability predicates, a smaller number will make this function quicker, similarly choose a larger number for low probabilities.
Returns:

index_generator – A generator of (indices, data value) tuples which make the predicate True.

Return type:

generator

See also

where(), nonzero()

Notes

This function is best used for finding the first, or first few, data values which match the predicate.

Examples

>>> a = np.sin(np.linspace(0, np.pi, 200))
>>> result = find(a, lambda arr: arr > 0.9)
>>> next(result)
((71, ), 0.900479032457)
>>> np.where(a > 0.9)[0][0]
71
schlichtanders.mynumpy.mean(iterable)[source]
schlichtanders.mynumpy.mean_gen(values)[source]