當前位置: 首頁>>代碼示例>>Python>>正文


Python umath.absolute方法代碼示例

本文整理匯總了Python中numpy.core.umath.absolute方法的典型用法代碼示例。如果您正苦於以下問題:Python umath.absolute方法的具體用法?Python umath.absolute怎麽用?Python umath.absolute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy.core.umath的用法示例。


在下文中一共展示了umath.absolute方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: approx

# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import absolute [as 別名]
def approx(a, b, fill_value=True, rtol=1e-5, atol=1e-8):
    """
    Returns true if all components of a and b are equal to given tolerances.

    If fill_value is True, masked values considered equal. Otherwise,
    masked values are considered unequal.  The relative error rtol should
    be positive and << 1.0 The absolute error atol comes into play for
    those elements of b that are very small or zero; it says how small a
    must be also.

    """
    m = mask_or(getmask(a), getmask(b))
    d1 = filled(a)
    d2 = filled(b)
    if d1.dtype.char == "O" or d2.dtype.char == "O":
        return np.equal(d1, d2).ravel()
    x = filled(masked_array(d1, copy=False, mask=m), fill_value).astype(float_)
    y = filled(masked_array(d2, copy=False, mask=m), 1).astype(float_)
    d = np.less_equal(umath.absolute(x - y), atol + rtol * umath.absolute(y))
    return d.ravel() 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:22,代碼來源:testutils.py

示例2: approx

# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import absolute [as 別名]
def approx (a, b, fill_value=True, rtol=1e-5, atol=1e-8):
    """Returns true if all components of a and b are equal subject to given tolerances.

If fill_value is True, masked values considered equal. Otherwise, masked values
are considered unequal.
The relative error rtol should be positive and << 1.0
The absolute error atol comes into play for those elements of b that are very
small or zero; it says how small a must be also.
    """
    m = mask_or(getmask(a), getmask(b))
    d1 = filled(a)
    d2 = filled(b)
    if d1.dtype.char == "O" or d2.dtype.char == "O":
        return np.equal(d1, d2).ravel()
    x = filled(masked_array(d1, copy=False, mask=m), fill_value).astype(float_)
    y = filled(masked_array(d2, copy=False, mask=m), 1).astype(float_)
    d = np.less_equal(umath.absolute(x - y), atol + rtol * umath.absolute(y))
    return d.ravel() 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:20,代碼來源:testutils.py

示例3: default_fill_value

# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import absolute [as 別名]
def default_fill_value (obj):
    "Function to calculate default fill value for an object."
    if isinstance(obj, float):
        return default_real_fill_value
    elif isinstance(obj, int) or isinstance(obj, long):
        return default_integer_fill_value
    elif isinstance(obj, bytes):
        return default_character_fill_value
    elif isinstance(obj, complex):
        return default_complex_fill_value
    elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):
        x = obj.dtype.char
        if x in typecodes['Float']:
            return default_real_fill_value
        if x in typecodes['Integer']:
            return default_integer_fill_value
        if x in typecodes['Complex']:
            return default_complex_fill_value
        if x in typecodes['Character']:
            return default_character_fill_value
        if x in typecodes['UnsignedInteger']:
            return umath.absolute(default_integer_fill_value)
        return default_object_fill_value
    else:
        return default_object_fill_value 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:27,代碼來源:ma.py

示例4: masked_values

# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import absolute [as 別名]
def masked_values (data, value, rtol=1.e-5, atol=1.e-8, copy=1):
    """
       masked_values(data, value, rtol=1.e-5, atol=1.e-8)
       Create a masked array; mask is nomask if possible.
       If copy==0, and otherwise possible, result
       may share data values with original array.
       Let d = filled(data, value). Returns d
       masked where abs(data-value)<= atol + rtol * abs(value)
       if d is of a floating point type. Otherwise returns
       masked_object(d, value, copy)
    """
    abs = umath.absolute
    d = filled(data, value)
    if issubclass(d.dtype.type, numeric.floating):
        m = umath.less_equal(abs(d-value), atol+rtol*abs(value))
        m = make_mask(m, flag=1)
        return array(d, mask = m, copy=copy,
                      fill_value=value)
    else:
        return masked_object(d, value, copy=copy) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:22,代碼來源:ma.py

示例5: test_abs_blocked

# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import absolute [as 別名]
def test_abs_blocked(self):
        "simd tests on abs"
        for dt in [np.float32, np.float64]:
            for out, inp, msg in _gen_alignment_data(dtype=dt, type='unary',
                                                     max_size=17):
                tgt = [ncu.absolute(i) for i in inp]
                np.absolute(inp, out=out)
                assert_equal(out, tgt, err_msg=msg)
                self.assertTrue((out >= 0).all())

                # will throw invalid flag depending on compiler optimizations
                with np.errstate(invalid='ignore'):
                    for v in [np.nan, -np.inf, np.inf]:
                        for i in range(inp.size):
                            d = np.arange(inp.size, dtype=dt)
                            inp[:] = -d
                            inp[i] = v
                            d[i] = -v if v == -np.inf else v
                            assert_array_equal(np.abs(inp), d, err_msg=msg)
                            np.abs(inp, out=out)
                            assert_array_equal(out, d, err_msg=msg) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:23,代碼來源:test_umath.py

示例6: test_abs_neg_blocked

# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import absolute [as 別名]
def test_abs_neg_blocked(self):
        # simd tests on abs, test all alignments for vz + 2 * (vs - 1) + 1
        for dt, sz in [(np.float32, 11), (np.float64, 5)]:
            for out, inp, msg in _gen_alignment_data(dtype=dt, type='unary',
                                                     max_size=sz):
                tgt = [ncu.absolute(i) for i in inp]
                np.absolute(inp, out=out)
                assert_equal(out, tgt, err_msg=msg)
                assert_((out >= 0).all())

                tgt = [-1*(i) for i in inp]
                np.negative(inp, out=out)
                assert_equal(out, tgt, err_msg=msg)

                for v in [np.nan, -np.inf, np.inf]:
                    for i in range(inp.size):
                        d = np.arange(inp.size, dtype=dt)
                        inp[:] = -d
                        inp[i] = v
                        d[i] = -v if v == -np.inf else v
                        assert_array_equal(np.abs(inp), d, err_msg=msg)
                        np.abs(inp, out=out)
                        assert_array_equal(out, d, err_msg=msg)

                        assert_array_equal(-inp, -1*inp, err_msg=msg)
                        d = -1 * inp
                        np.negative(inp, out=out)
                        assert_array_equal(out, d, err_msg=msg) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:30,代碼來源:test_umath.py

示例7: test_abs_neg_blocked

# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import absolute [as 別名]
def test_abs_neg_blocked(self):
        # simd tests on abs, test all alignments for vz + 2 * (vs - 1) + 1
        for dt, sz in [(np.float32, 11), (np.float64, 5)]:
            for out, inp, msg in _gen_alignment_data(dtype=dt, type='unary',
                                                     max_size=sz):
                tgt = [ncu.absolute(i) for i in inp]
                np.absolute(inp, out=out)
                assert_equal(out, tgt, err_msg=msg)
                self.assertTrue((out >= 0).all())

                tgt = [-1*(i) for i in inp]
                np.negative(inp, out=out)
                assert_equal(out, tgt, err_msg=msg)

                # will throw invalid flag depending on compiler optimizations
                with np.errstate(invalid='ignore'):
                    for v in [np.nan, -np.inf, np.inf]:
                        for i in range(inp.size):
                            d = np.arange(inp.size, dtype=dt)
                            inp[:] = -d
                            inp[i] = v
                            d[i] = -v if v == -np.inf else v
                            assert_array_equal(np.abs(inp), d, err_msg=msg)
                            np.abs(inp, out=out)
                            assert_array_equal(out, d, err_msg=msg)

                            assert_array_equal(-inp, -1*inp, err_msg=msg)
                            np.negative(inp, out=out)
                            assert_array_equal(out, -1*inp, err_msg=msg) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:31,代碼來源:test_umath.py

示例8: __call__

# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import absolute [as 別名]
def __call__ (self, x):
        "Execute the call behavior."
        return umath.less(umath.absolute(umath.cos(x)), self.eps) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:5,代碼來源:ma.py

示例9: __abs__

# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import absolute [as 別名]
def __abs__(self):
        "Return absolute(self)"
        return absolute(self) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:5,代碼來源:ma.py


注:本文中的numpy.core.umath.absolute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。