本文整理汇总了Python中numpy.frompyfunc方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.frompyfunc方法的具体用法?Python numpy.frompyfunc怎么用?Python numpy.frompyfunc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.frompyfunc方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_ufunc
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import frompyfunc [as 别名]
def set_ufunc(self, scalar_op):
# This is probably a speed up of the implementation
if isinstance(scalar_op, theano.scalar.basic.Add):
self.ufunc = numpy.add
elif isinstance(scalar_op, theano.scalar.basic.Mul):
self.ufunc = numpy.multiply
elif isinstance(scalar_op, theano.scalar.basic.Maximum):
self.ufunc = numpy.maximum
elif isinstance(scalar_op, theano.scalar.basic.Minimum):
self.ufunc = numpy.minimum
elif isinstance(scalar_op, theano.scalar.basic.AND):
self.ufunc = numpy.bitwise_and
elif isinstance(scalar_op, theano.scalar.basic.OR):
self.ufunc = numpy.bitwise_or
elif isinstance(scalar_op, theano.scalar.basic.XOR):
self.ufunc = numpy.bitwise_xor
else:
self.ufunc = numpy.frompyfunc(scalar_op.impl, 2, 1)
示例2: gcd
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import frompyfunc [as 别名]
def gcd(lst):
"""
greatest common divisor function using library functions
Parameters
----------
lst: array-like
array of integer values for which the greatest common divisor should be
determined
Returns
-------
gcd: int
"""
if numpy.version.version >= '1.15.0':
return numpy.gcd.reduce(lst)
elif sys.version_info >= (3, 5):
gcdfunc = numpy.frompyfunc(math.gcd, 2, 1)
else:
gcdfunc = numpy.frompyfunc(fractions.gcd, 2, 1)
return numpy.ufunc.reduce(gcdfunc, lst)
示例3: test_frompyfunc_endian
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import frompyfunc [as 别名]
def test_frompyfunc_endian(self):
# Ticket #503
from math import radians
uradians = np.frompyfunc(radians, 1, 1)
big_endian = np.array([83.4, 83.5], dtype='>f8')
little_endian = np.array([83.4, 83.5], dtype='<f8')
assert_almost_equal(uradians(big_endian).astype(float),
uradians(little_endian).astype(float))
示例4: test_frompyfunc_many_args
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import frompyfunc [as 别名]
def test_frompyfunc_many_args(self):
# gh-5672
def passer(*args):
pass
assert_raises(ValueError, np.frompyfunc, passer, 32, 1)
示例5: test_frompyfunc_nout_0
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import frompyfunc [as 别名]
def test_frompyfunc_nout_0(self):
# gh-2014
def f(x):
x[0], x[-1] = x[-1], x[0]
uf = np.frompyfunc(f, 1, 0)
a = np.array([[1, 2, 3], [4, 5], [6, 7, 8, 9]])
assert_equal(uf(a), ())
assert_array_equal(a, [[3, 2, 1], [5, 4], [9, 7, 8, 6]])
示例6: _maybe_convert
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import frompyfunc [as 别名]
def _maybe_convert(values, val_kind, encoding, errors):
if _need_convert(val_kind):
conv = _get_converter(val_kind, encoding, errors)
# conv = np.frompyfunc(conv, 1, 1)
values = conv(values)
return values
示例7: test_frompyfunc_endian
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import frompyfunc [as 别名]
def test_frompyfunc_endian(self, level=rlevel):
# Ticket #503
from math import radians
uradians = np.frompyfunc(radians, 1, 1)
big_endian = np.array([83.4, 83.5], dtype='>f8')
little_endian = np.array([83.4, 83.5], dtype='<f8')
assert_almost_equal(uradians(big_endian).astype(float),
uradians(little_endian).astype(float))
示例8: __setstate__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import frompyfunc [as 别名]
def __setstate__(self, d):
super(Elemwise, self).__setstate__(d)
self.ufunc = None
self.nfunc = None
if getattr(self, 'nfunc_spec', None):
self.nfunc = getattr(numpy, self.nfunc_spec[0])
elif 0 < self.scalar_op.nin < 32:
self.ufunc = numpy.frompyfunc(self.scalar_op.impl,
self.scalar_op.nin,
self.scalar_op.nout)
self._rehash()
示例9: prepare_node
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import frompyfunc [as 别名]
def prepare_node(self, node, storage_map, compute_map):
# Postpone the ufunc building to the last minutes
# NumPy ufunc support only up to 31 inputs.
# But our c code support more.
if (len(node.inputs) < 32 and
(self.nfunc is None or
self.scalar_op.nin != len(node.inputs)) and
self.ufunc is None):
ufunc = numpy.frompyfunc(self.scalar_op.impl,
len(node.inputs),
self.scalar_op.nout)
if self.scalar_op.nin > 0:
# We can reuse it for many nodes
self.ufunc = ufunc
else:
node.tag.ufunc = ufunc
# Numpy ufuncs will sometimes perform operations in
# float16, in particular when the input is int8.
# This is not something that we want, and we do not
# do it in the C code, so we specify that the computation
# should be carried out in the returned dtype.
# This is done via the "sig" kwarg of the ufunc, its value
# should be something like "ff->f", where the characters
# represent the dtype of the inputs and outputs.
# NumPy 1.10.1 raise an error when giving the signature
# when the input is complex. So add it only when inputs is int.
out_dtype = node.outputs[0].dtype
if (out_dtype in float_dtypes and
isinstance(self.nfunc, numpy.ufunc) and
node.inputs[0].dtype in discrete_dtypes):
char = numpy.sctype2char(out_dtype)
sig = char * node.nin + '->' + char * node.nout
node.tag.sig = sig
示例10: test_frompyfunc_endian
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import frompyfunc [as 别名]
def test_frompyfunc_endian(self, level=rlevel):
"""Ticket #503"""
from math import radians
uradians = np.frompyfunc(radians, 1, 1)
big_endian = np.array([83.4, 83.5], dtype='>f8')
little_endian = np.array([83.4, 83.5], dtype='<f8')
assert_almost_equal(uradians(big_endian).astype(float),
uradians(little_endian).astype(float))
示例11: _get_object_array
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import frompyfunc [as 别名]
def _get_object_array(self):
freq = self.freq
boxfunc = lambda x: Period(ordinal=x, freq=freq)
boxer = np.frompyfunc(boxfunc, 1, 1)
return boxer(self.values)
示例12: _maybe_convert
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import frompyfunc [as 别名]
def _maybe_convert(values, val_kind, encoding):
if _need_convert(val_kind):
conv = _get_converter(val_kind, encoding)
# conv = np.frompyfunc(conv, 1, 1)
values = conv(values)
return values
示例13: _object_dtype_isnan
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import frompyfunc [as 别名]
def _object_dtype_isnan(X):
return np.frompyfunc(lambda x: x != x, 1, 1)(X).astype(bool)
示例14: render
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import frompyfunc [as 别名]
def render(imgsize):
y, x = np.ogrid[1: -1: imgsize*2j, -1: 1: imgsize*2j]
z = x + y * 1j
img = np.frompyfunc(iterate, 1, 1)(z).astype(np.float)
fig = plt.figure(figsize=(imgsize/100.0, imgsize/100.0), dpi=100)
ax = fig.add_axes([0, 0, 1, 1], aspect=1)
ax.axis('off')
ax.imshow(img, cmap='hot')
fig.savefig('newton.png')