Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def as_scalar(value):
"""Like np.asscalar, but also works on scalar values (not just ndarrays)
"""
return np.array(value).item()
def to_str(value):
"""Convert a (possibly bytes) string to unicode, which is comparable to
strings on all Python versions
class partial_by_order(object):
"""
>>> f = partial_by_order(add, [(1, 10)])
>>> f(5)
15
"""
def __init__(self, op, other):
if (not isinstance(other, list) or
not all(isinstance(o, tuple) and len(o) == 2 for o in other)):
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.