當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。