当前位置: 首页>>代码示例>>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;未经允许,请勿转载。