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


Python numpy.floating方法代碼示例

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


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

示例1: _handle_date_column

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import floating [as 別名]
def _handle_date_column(col, utc=None, format=None):
    if isinstance(format, dict):
        return to_datetime(col, errors='ignore', **format)
    else:
        # Allow passing of formatting string for integers
        # GH17855
        if format is None and (issubclass(col.dtype.type, np.floating) or
                               issubclass(col.dtype.type, np.integer)):
            format = 's'
        if format in ['D', 'd', 'h', 'm', 's', 'ms', 'us', 'ns']:
            return to_datetime(col, errors='coerce', unit=format, utc=utc)
        elif is_datetime64tz_dtype(col):
            # coerce to UTC timezone
            # GH11216
            return to_datetime(col, utc=True)
        else:
            return to_datetime(col, errors='coerce', format=format, utc=utc) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:sql.py

示例2: default

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import floating [as 別名]
def default(self, obj):
		if isinstance(obj, np.integer):
			return int(obj)
		elif isinstance(obj, np.floating):
			return float(obj)
		elif isinstance(obj, np.ndarray):
			return obj.tolist()
		elif isinstance(obj, WhitespaceNLP.Doc):
			return repr(obj)
		elif isinstance(obj, AsianNLP.Doc):
			return repr(obj)
		elif 'spacy' in sys.modules:
			import spacy
			if isinstance(obj, spacy.tokens.doc.Doc):
				return repr(obj)
		else:
			return super(MyEncoder, self).default(obj) 
開發者ID:JasonKessler,項目名稱:scattertext,代碼行數:19,代碼來源:VizDataAdapter.py

示例3: do

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import floating [as 別名]
def do(self, a, b):
        arr = np.asarray(a)
        m, n = arr.shape
        u, s, vt = linalg.svd(a, 0)
        x, residuals, rank, sv = linalg.lstsq(a, b)
        if m <= n:
            assert_almost_equal(b, dot(a, x))
            assert_equal(rank, m)
        else:
            assert_equal(rank, n)
        assert_almost_equal(sv, sv.__array_wrap__(s))
        if rank == n and m > n:
            expect_resids = (
                np.asarray(abs(np.dot(a, x) - b)) ** 2).sum(axis=0)
            expect_resids = np.asarray(expect_resids)
            if len(np.asarray(b).shape) == 1:
                expect_resids.shape = (1,)
                assert_equal(residuals.shape, expect_resids.shape)
        else:
            expect_resids = np.array([]).view(type(x))
        assert_almost_equal(residuals, expect_resids)
        assert_(np.issubdtype(residuals.dtype, np.floating))
        assert_(imply(isinstance(b, matrix), isinstance(x, matrix)))
        assert_(imply(isinstance(b, matrix), isinstance(residuals, matrix))) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:26,代碼來源:test_linalg.py

示例4: parse_type

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import floating [as 別名]
def parse_type(self, hdat, dataobj=None):
        dtype = super(MGHImageType, self).parse_type(hdat, dataobj=dataobj)
        if   np.issubdtype(dtype, np.floating): dtype = np.float32
        elif np.issubdtype(dtype, np.int8):     dtype = np.int8
        elif np.issubdtype(dtype, np.int16):    dtype = np.int16
        elif np.issubdtype(dtype, np.integer):  dtype = np.int32
        else: raise ValueError('Could not deduce appropriate MGH type for dtype %s' % dtype)
        return dtype 
開發者ID:noahbenson,項目名稱:neuropythy,代碼行數:10,代碼來源:images.py

示例5: __modify_schema__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import floating [as 別名]
def __modify_schema__(cls, field_schema: Dict[str, Any]) -> None:
        dt = cls._dtype
        if dt is int or np.issubdtype(dt, np.integer):
            items = {"type": "number", "multipleOf": 1.0}
        elif dt is float or np.issubdtype(dt, np.floating):
            items = {"type": "number"}
        elif dt is str or np.issubdtype(dt, np.string_):
            items = {"type": "string"}
        elif dt is bool or np.issubdtype(dt, np.bool_):
            items = {"type": "boolean"}
        field_schema.update(type="array", items=items) 
開發者ID:MolSSI,項目名稱:QCElemental,代碼行數:13,代碼來源:types.py

示例6: default

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import floating [as 別名]
def default(self, obj):
        if isinstance(obj, numpy.integer):
            return int(obj)
        elif isinstance(obj, numpy.floating):
            return float(obj)
        elif isinstance(obj, numpy.ndarray):
            return obj.tolist()
        else:
            return super(NpEncoder, self).default(obj) 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:11,代碼來源:shci.py

示例7: default

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import floating [as 別名]
def default(self, obj):
        if isinstance(obj, np.integer):
            return int(obj)
        elif isinstance(obj, np.floating):
            return float(obj)
        elif isinstance(obj, (np.ndarray, pd.Series)):
            return obj.tolist()
        else:
            return str(obj) 
開發者ID:ConvLab,項目名稱:ConvLab,代碼行數:11,代碼來源:util.py

示例8: default

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import floating [as 別名]
def default(self, obj):
        """Encode by default."""
        if isinstance(obj, np.integer) or isinstance(obj, np.int64):
            return int(obj)
        elif isinstance(obj, np.floating):
            return float(obj)
        elif isinstance(obj, np.ndarray):
            return obj.tolist()
        else:
            return super(NumpyEncoder, self).default(obj) 
開發者ID:predicador37,項目名稱:pyjstat,代碼行數:12,代碼來源:pyjstat.py

示例9: test_asfarray

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import floating [as 別名]
def test_asfarray(self):
        a = asfarray(np.array([1, 2, 3]))
        assert_equal(a.__class__, np.ndarray)
        assert_(np.issubdtype(a.dtype, np.floating))

        # previously this would infer dtypes from arrays, unlike every single
        # other numpy function
        assert_raises(TypeError,
            asfarray, np.array([1, 2, 3]), dtype=np.array(1.0)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:11,代碼來源:test_type_check.py

示例10: test_type

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import floating [as 別名]
def test_type(self):
        # Check the type of the returned histogram
        a = np.arange(10) + .5
        h, b = histogram(a)
        assert_(np.issubdtype(h.dtype, np.integer))

        h, b = histogram(a, density=True)
        assert_(np.issubdtype(h.dtype, np.floating))

        h, b = histogram(a, weights=np.ones(10, int))
        assert_(np.issubdtype(h.dtype, np.integer))

        h, b = histogram(a, weights=np.ones(10, float))
        assert_(np.issubdtype(h.dtype, np.floating)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:16,代碼來源:test_histograms.py

示例11: test_bin_edge_cases

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import floating [as 別名]
def test_bin_edge_cases(self):
        # Ensure that floating-point computations correctly place edge cases.
        arr = np.array([337, 404, 739, 806, 1007, 1811, 2012])
        hist, edges = np.histogram(arr, bins=8296, range=(2, 2280))
        mask = hist > 0
        left_edges = edges[:-1][mask]
        right_edges = edges[1:][mask]
        for x, left, right in zip(arr, left_edges, right_edges):
            assert_(x >= left)
            assert_(x < right) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_histograms.py

示例12: _getconv

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import floating [as 別名]
def _getconv(dtype):
    """ Find the correct dtype converter. Adapted from matplotlib """

    def floatconv(x):
        x.lower()
        if '0x' in x:
            return float.fromhex(x)
        return float(x)

    typ = dtype.type
    if issubclass(typ, np.bool_):
        return lambda x: bool(int(x))
    if issubclass(typ, np.uint64):
        return np.uint64
    if issubclass(typ, np.int64):
        return np.int64
    if issubclass(typ, np.integer):
        return lambda x: int(float(x))
    elif issubclass(typ, np.longdouble):
        return np.longdouble
    elif issubclass(typ, np.floating):
        return floatconv
    elif issubclass(typ, complex):
        return lambda x: complex(asstr(x).replace('+-', '-'))
    elif issubclass(typ, np.bytes_):
        return asbytes
    elif issubclass(typ, np.unicode_):
        return asunicode
    else:
        return asstr

# amount of lines loadtxt reads in one chunk, can be overridden for testing 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:34,代碼來源:npyio.py

示例13: do

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import floating [as 別名]
def do(self, a, b, tags):
        arr = np.asarray(a)
        m, n = arr.shape
        u, s, vt = linalg.svd(a, 0)
        x, residuals, rank, sv = linalg.lstsq(a, b, rcond=-1)
        if m == 0:
            assert_((x == 0).all())
        if m <= n:
            assert_almost_equal(b, dot(a, x))
            assert_equal(rank, m)
        else:
            assert_equal(rank, n)
        assert_almost_equal(sv, sv.__array_wrap__(s))
        if rank == n and m > n:
            expect_resids = (
                np.asarray(abs(np.dot(a, x) - b)) ** 2).sum(axis=0)
            expect_resids = np.asarray(expect_resids)
            if np.asarray(b).ndim == 1:
                expect_resids.shape = (1,)
                assert_equal(residuals.shape, expect_resids.shape)
        else:
            expect_resids = np.array([]).view(type(x))
        assert_almost_equal(residuals, expect_resids)
        assert_(np.issubdtype(residuals.dtype, np.floating))
        assert_(consistent_subclass(x, b))
        assert_(consistent_subclass(residuals, b)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:28,代碼來源:test_linalg.py

示例14: _get_format_function

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import floating [as 別名]
def _get_format_function(data, **options):
    """
    find the right formatting function for the dtype_
    """
    dtype_ = data.dtype
    dtypeobj = dtype_.type
    formatdict = _get_formatdict(data, **options)
    if issubclass(dtypeobj, _nt.bool_):
        return formatdict['bool']()
    elif issubclass(dtypeobj, _nt.integer):
        if issubclass(dtypeobj, _nt.timedelta64):
            return formatdict['timedelta']()
        else:
            return formatdict['int']()
    elif issubclass(dtypeobj, _nt.floating):
        if issubclass(dtypeobj, _nt.longfloat):
            return formatdict['longfloat']()
        else:
            return formatdict['float']()
    elif issubclass(dtypeobj, _nt.complexfloating):
        if issubclass(dtypeobj, _nt.clongfloat):
            return formatdict['longcomplexfloat']()
        else:
            return formatdict['complexfloat']()
    elif issubclass(dtypeobj, (_nt.unicode_, _nt.string_)):
        return formatdict['numpystr']()
    elif issubclass(dtypeobj, _nt.datetime64):
        return formatdict['datetime']()
    elif issubclass(dtypeobj, _nt.object_):
        return formatdict['object']()
    elif issubclass(dtypeobj, _nt.void):
        if dtype_.names is not None:
            return StructuredVoidFormat.from_data(data, **options)
        else:
            return formatdict['void']()
    else:
        return formatdict['numpystr']() 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:39,代碼來源:arrayprint.py

示例15: test_abstract

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import floating [as 別名]
def test_abstract(self):
        assert_(issubclass(np.number, numbers.Number))

        assert_(issubclass(np.inexact, numbers.Complex))
        assert_(issubclass(np.complexfloating, numbers.Complex))
        assert_(issubclass(np.floating, numbers.Real))

        assert_(issubclass(np.integer, numbers.Integral))
        assert_(issubclass(np.signedinteger, numbers.Integral))
        assert_(issubclass(np.unsignedinteger, numbers.Integral)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_abc.py


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