当前位置: 首页>>代码示例>>Python>>正文


Python numpy.frompyfunc方法代码示例

本文整理汇总了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) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:20,代码来源:elemwise.py

示例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) 
开发者ID:dkriegner,项目名称:xrayutilities,代码行数:23,代码来源:misc.py

示例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)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_regression.py

示例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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_regression.py

示例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]]) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_regression.py

示例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 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:pytables.py

示例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)) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:10,代码来源:test_regression.py

示例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() 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:13,代码来源:elemwise.py

示例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 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:38,代码来源:elemwise.py

示例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)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_regression.py

示例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) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:period.py

示例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 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:8,代码来源:pytables.py

示例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) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:4,代码来源:fixes.py

示例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') 
开发者ID:neozhaoliang,项目名称:pywonderland,代码行数:11,代码来源:newton.py


注:本文中的numpy.frompyfunc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。