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


Python numpy.half方法代碼示例

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


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

示例1: test_floating_overflow

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import half [as 別名]
def test_floating_overflow(self):
        """ Strings containing an unrepresentable float overflow """
        fhalf = np.half('1e10000')
        assert_equal(fhalf, np.inf)
        fsingle = np.single('1e10000')
        assert_equal(fsingle, np.inf)
        fdouble = np.double('1e10000')
        assert_equal(fdouble, np.inf)
        flongdouble = assert_warns(RuntimeWarning, np.longdouble, '1e10000')
        assert_equal(flongdouble, np.inf)

        fhalf = np.half('-1e10000')
        assert_equal(fhalf, -np.inf)
        fsingle = np.single('-1e10000')
        assert_equal(fsingle, -np.inf)
        fdouble = np.double('-1e10000')
        assert_equal(fdouble, -np.inf)
        flongdouble = assert_warns(RuntimeWarning, np.longdouble, '-1e10000')
        assert_equal(flongdouble, -np.inf) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:21,代碼來源:test_scalar_ctors.py

示例2: _asfarray

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import half [as 別名]
def _asfarray(x):
    """Like numpy asfarray, except that it does not modify x dtype if x is
    already an array with a float dtype, and do not cast complex types to
    real."""
    if hasattr(x, "dtype") and x.dtype.char in numpy.typecodes["AllFloat"]:
        # 'dtype' attribute does not ensure that the
        # object is an ndarray (e.g. Series class
        # from the pandas library)
        if x.dtype == numpy.half:
            # no half-precision routines, so convert to single precision
            return numpy.asarray(x, dtype=numpy.float32)
        return numpy.asarray(x, dtype=x.dtype)
    else:
        # We cannot use asfarray directly because it converts sequences of
        # complex to sequence of real
        ret = numpy.asarray(x)
        if ret.dtype == numpy.half:
            return numpy.asarray(ret, dtype=numpy.float32)
        elif ret.dtype.char not in numpy.typecodes["AllFloat"]:
            return numpy.asfarray(x)
        return ret 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:23,代碼來源:basic.py

示例3: test_roundtrip_half

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import half [as 別名]
def test_roundtrip_half(self):
        half_list = [
            1.0,
            -2.0,
            6.5504 * 10**4, #  (max half precision)
            2**-14, # ~= 6.10352 * 10**-5 (minimum positive normal)
            2**-24, # ~= 5.96046 * 10**-8 (minimum strictly positive subnormal)
            0.0,
            -0.0,
            float('+inf'),
            float('-inf'),
            0.333251953125, # ~= 1/3
        ]

        x = np.array(half_list, dtype='>e')
        self._check_roundtrip(x)
        x = np.array(half_list, dtype='<e')
        self._check_roundtrip(x) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:20,代碼來源:test_multiarray.py

示例4: test_singleton

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import half [as 別名]
def test_singleton(self):
        ftype = finfo(half)
        ftype2 = finfo(half)
        assert_equal(id(ftype), id(ftype2)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:6,代碼來源:test_getlimits.py

示例5: test_precision

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import half [as 別名]
def test_precision(self):
        # not looping results in a useful stack trace upon failure
        self.do_precision(np.half, np.single)
        self.do_precision(np.half, np.double)
        self.do_precision(np.half, np.longdouble)
        self.do_precision(np.single, np.double)
        self.do_precision(np.single, np.longdouble)
        self.do_precision(np.double, np.longdouble) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:10,代碼來源:test_histograms.py

示例6: _generate_latlon_arrays

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import half [as 別名]
def _generate_latlon_arrays(array, transformer, geotransform):
    
    def generate_latlon_for_here(x, y):
        return generate_latlon(x, y, geotransform, transformer)

    # The crude way. Ask someone if it is doable.
    top_lat, left_lon = generate_latlon_for_here(0,0)
    bottom_lat, right_lon = generate_latlon_for_here(array.shape[0]-1, array.shape[1]-1)

    lat_list = np.linspace(top_lat, bottom_lat, array.shape[1], dtype=np.half)
    lon_list = np.linspace(left_lon, right_lon, array.shape[0], dtype=np.half)
    lat_array = np.stack([lat_list]*array.shape[0])
    lon_array = np.stack([lon_list]*array.shape[1]).T

    return lat_array, lon_array 
開發者ID:clcr,項目名稱:pyeo,代碼行數:17,代碼來源:terrain_correction.py

示例7: calc_azimuth_array

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import half [as 別名]
def calc_azimuth_array(lat_array, lon_array, raster_datetime):
    def calc_azimuth_for_datetime(lat, lon):
        return solar.get_azimuth_fast(lat, lon, raster_datetime).astype(np.dtype(np.half))
    return np.array(list(map(calc_azimuth_for_datetime, lat_array, lon_array))) 
開發者ID:clcr,項目名稱:pyeo,代碼行數:6,代碼來源:terrain_correction.py

示例8: test_export_record

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import half [as 別名]
def test_export_record(self):
        dt = [('a', 'b'),
              ('b', 'h'),
              ('c', 'i'),
              ('d', 'l'),
              ('dx', 'q'),
              ('e', 'B'),
              ('f', 'H'),
              ('g', 'I'),
              ('h', 'L'),
              ('hx', 'Q'),
              ('i', np.single),
              ('j', np.double),
              ('k', np.longdouble),
              ('ix', np.csingle),
              ('jx', np.cdouble),
              ('kx', np.clongdouble),
              ('l', 'S4'),
              ('m', 'U4'),
              ('n', 'V3'),
              ('o', '?'),
              ('p', np.half),
             ]
        x = np.array(
                [(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    asbytes('aaaa'), 'bbbb', asbytes('   '), True, 1.0)],
                dtype=dt)
        y = memoryview(x)
        assert_equal(y.shape, (1,))
        assert_equal(y.ndim, 1)
        assert_equal(y.suboffsets, EMPTY)

        sz = sum([dtype(b).itemsize for a, b in dt])
        if dtype('l').itemsize == 4:
            assert_equal(y.format, 'T{b:a:=h:b:i:c:l:d:^q:dx:B:e:@H:f:=I:g:L:h:^Q:hx:=f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p:}')
        else:
            assert_equal(y.format, 'T{b:a:=h:b:i:c:q:d:^q:dx:B:e:@H:f:=I:g:Q:h:^Q:hx:=f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p:}')
        # Cannot test if NPY_RELAXED_STRIDES_CHECKING changes the strides
        if not (np.ones(1).strides[0] == np.iinfo(np.intp).max):
            assert_equal(y.strides, (sz,))
        assert_equal(y.itemsize, sz) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:43,代碼來源:test_multiarray.py


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