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


Python numpy.maximum_sctype方法代碼示例

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


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

示例1: check_int_a2f

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import maximum_sctype [as 別名]
def check_int_a2f(in_type, out_type):
    # Check that array to / from file returns roughly the same as input
    big_floater = np.maximum_sctype(np.float)
    info = type_info(in_type)
    this_min, this_max = info['min'], info['max']
    if not in_type in np.sctypes['complex']:
        data = np.array([this_min, this_max], in_type)
        # Bug in numpy 1.6.2 on PPC leading to infs - abort
        if not np.all(np.isfinite(data)):
            if DEBUG:
                print 'Hit PPC max -> inf bug; skip in_type %s' % in_type
            return
    else: # Funny behavior with complex256
        data = np.zeros((2,), in_type)
        data[0] = this_min + 0j
        data[1] = this_max + 0j
    str_io = BytesIO()
    try:
        scale, inter, mn, mx = calculate_scale(data, out_type, True)
    except ValueError:
        if DEBUG:
            print in_type, out_type, sys.exc_info()[1]
        return
    array_to_file(data, str_io, out_type, 0, inter, scale, mn, mx)
    data_back = array_from_file(data.shape, out_type, str_io)
    data_back = apply_read_scaling(data_back, scale, inter)
    assert_true(np.allclose(big_floater(data), big_floater(data_back)))
    # Try with analyze-size scale and inter
    scale32 = np.float32(scale)
    inter32 = np.float32(inter)
    if scale32 == np.inf or inter32 == np.inf:
        return
    data_back = array_from_file(data.shape, out_type, str_io)
    data_back = apply_read_scaling(data_back, scale32, inter32)
    # Clip at extremes to remove inf
    info = type_info(in_type)
    out_min, out_max = info['min'], info['max']
    assert_true(np.allclose(big_floater(data),
                            big_floater(np.clip(data_back, out_min, out_max)))) 
開發者ID:ME-ICA,項目名稱:me-ica,代碼行數:41,代碼來源:test_scaling.py

示例2: test_int

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import maximum_sctype [as 別名]
def test_int(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['int'][-1]) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:4,代碼來源:test_numerictypes.py

示例3: test_uint

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import maximum_sctype [as 別名]
def test_uint(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['uint'][-1]) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:4,代碼來源:test_numerictypes.py

示例4: test_float

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import maximum_sctype [as 別名]
def test_float(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['float'][-1]) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:4,代碼來源:test_numerictypes.py

示例5: test_complex

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import maximum_sctype [as 別名]
def test_complex(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['complex'][-1]) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:4,代碼來源:test_numerictypes.py

示例6: test_other

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import maximum_sctype [as 別名]
def test_other(self, t):
        assert_equal(np.maximum_sctype(t), t) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:4,代碼來源:test_numerictypes.py

示例7: test_scale_min_max

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import maximum_sctype [as 別名]
def test_scale_min_max():
    mx_dt = np.maximum_sctype(np.float)
    for tp in np.sctypes['uint'] + np.sctypes['int']:
        info = np.iinfo(tp)
        # Need to pump up to max fp type to contain python longs
        imin = np.array(info.min, dtype=mx_dt)
        imax = np.array(info.max, dtype=mx_dt)
        value_pairs = (
            (0, imax),
            (imin, 0),
            (imin, imax),
            (1, 10),
            (-1, -1),
            (1, 1),
            (-10, -1),
            (-100, 10))
        for mn, mx in value_pairs:
            # with intercept
            scale, inter = scale_min_max(mn, mx, tp, True)
            if mx-mn:
                assert_array_almost_equal, (mx-inter) / scale, imax
                assert_array_almost_equal, (mn-inter) / scale, imin
            else:
                assert_equal, (scale, inter), (1.0, mn)
            # without intercept
            if imin == 0 and mn < 0 and mx > 0:
                (assert_raises, ValueError,
                       scale_min_max, mn, mx, tp, False)
                continue
            scale, inter = scale_min_max(mn, mx, tp, False)
            assert_equal, inter, 0.0
            if mn == 0 and mx == 0:
                assert_equal, scale, 1.0
                continue
            sc_mn = mn / scale
            sc_mx = mx / scale
            assert_true, sc_mn >= imin
            assert_true, sc_mx <= imax
            if imin == 0:
                if mx > 0: # numbers all +ve
                    assert_array_almost_equal, mx / scale, imax
                else: # numbers all -ve
                    assert_array_almost_equal, mn / scale, imax
                continue
            if abs(mx) >= abs(mn):
                assert_array_almost_equal, mx / scale, imax
            else:
                assert_array_almost_equal, mn / scale, imin 
開發者ID:ME-ICA,項目名稱:me-ica,代碼行數:50,代碼來源:test_scaling.py


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