_lib._util

Module Contents

Classes

Functions

_valarray(shape, value=None, typecode=None)

Return an array of all value.

_lazywhere(cond, arrays, f, fillvalue=None, f2=None)

np.where(cond, x, fillvalue) always evaluates x even where cond is False. This one only evaluates f(arr1[cond], arr2[cond], …). For example, >>> a, b = np.array([1, 2, 3, 4]), np.array([5, 6, 7, 8]) >>> def f(a, b):

return a*b
>>> _lazywhere(a > 2, (a, b), f, np.nan)
array([ nan,  nan,  21.,  32.])

Notice it assumes that all arrays are of the same shape, or can be broadcasted together.

_lazyselect(condlist, choicelist, arrays, default=0)

Mimic np.select(condlist, choicelist).

Notice it assumes that all arrays are of the same shape, or can be broadcasted together.

All functions in choicelist must accept array arguments in the order given in arrays and must return an array of the same shape as broadcasted arrays.

>>> x = np.arange(6)
>>> np.select([x <3, x > 3], [x**2, x**3], default=0)
array([  0,   1,   4,   0,  64, 125])
>>> _lazyselect([x < 3, x > 3], [lambda x: x**2, lambda x: x**3], (x,))
array([   0.,    1.,    4.,   0.,   64.,  125.])
>>> a = -np.ones_like(x)
>>> _lazyselect([x < 3, x > 3],
...             [lambda x, a: x**2, lambda x, a: a * x**3],
...             (x, a), default=np.nan)
array([   0.,    1.,    4.,   nan,  -64., -125.])
_aligned_zeros(shape, dtype=float, order="C", align=None)

Allocate a new ndarray with aligned memory.

Primary use case for this currently is working around a f2py issue in Numpy 1.9.1, where dtype.alignment is such that np.zeros() does not necessarily create arrays aligned up to it.

_prune_array(array)

Return an array equivalent to the input array. If the input array is a view of a much larger array, copy its contents to a newly allocated array. Otherwise, return the input unchaged.

class DeprecatedImport(old_module_name, new_module_name)

Deprecated import, with redirection + warning.

Suppose you previously had in some module:

from foo import spam

If this has to be deprecated, do:

spam = DeprecatedImport("foo.spam", "baz")

to redirect users to use “baz” module instead.

__init__(old_module_name, new_module_name)
__dir__()
__getattr__(name)
check_random_state(seed)

Turn seed into a np.random.RandomState instance

If seed is None (or np.random), return the RandomState singleton used by np.random. If seed is an int, return a new RandomState instance seeded with seed. If seed is already a RandomState instance, return it. Otherwise raise ValueError.

_asarray_validated(a, check_finite=True, sparse_ok=False, objects_ok=False, mask_ok=False, as_inexact=False)

Helper function for scipy argument validation.

Many scipy linear algebra functions do support arbitrary array-like input arguments. Examples of commonly unsupported inputs include matrices containing inf/nan, sparse matrix representations, and matrices with complicated elements.

a : array_like
The array-like input.
check_finite : bool, optional
Whether to check that the input matrices contain only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs. Default: True
sparse_ok : bool, optional
True if scipy sparse matrices are allowed.
objects_ok : bool, optional
True if arrays with dype(‘O’) are allowed.
mask_ok : bool, optional
True if masked arrays are allowed.
as_inexact : bool, optional
True to convert the input array to a np.inexact dtype.
ret : ndarray
The converted validated array.
getargspec_no_self(func)

inspect.getargspec replacement using inspect.signature.

inspect.getargspec is deprecated in python 3. This is a replacement based on the (new in python 3.3) inspect.signature.

func : callable
A callable to inspect
argspec : ArgSpec(args, varargs, varkw, defaults)
This is similar to the result of inspect.getargspec(func) under python 2.x. NOTE: if the first argument of func is self, it is not, I repeat not included in argspec.args. This is done for consistency between inspect.getargspec() under python 2.x, and inspect.signature() under python 3.x.
getargspec_no_self(func)

inspect.getargspec replacement for compatibility with python 3.x.

inspect.getargspec is deprecated in python 3. This wraps it, and removes self from the argument list of func, if present. This is done for forward compatibility with python 3.

func : callable
A callable to inspect
argspec : ArgSpec(args, varargs, varkw, defaults)
This is similar to the result of inspect.getargspec(func) under python 2.x. NOTE: if the first argument of func is self, it is not, I repeat not included in argspec.args. This is done for consistency between inspect.getargspec() under python 2.x, and inspect.signature() under python 3.x.