• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python compat.long函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.compat.long函数的典型用法代码示例。如果您正苦于以下问题:Python long函数的具体用法?Python long怎么用?Python long使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了long函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_basic

 def test_basic(self):
     assert_(np.isscalar(3))
     assert_(not np.isscalar([3]))
     assert_(not np.isscalar((3,)))
     assert_(np.isscalar(3j))
     assert_(np.isscalar(long(10)))
     assert_(np.isscalar(4.0))
开发者ID:dyao-vu,项目名称:meta-core,代码行数:7,代码来源:test_type_check.py


示例2: check_function

    def check_function(self, t):
        assert_( t(123)==123, repr(t(123)))
        assert_( t(123.6)==123)
        assert_( t(long(123))==123)
        assert_( t('123')==123)
        assert_( t(-123)==-123)
        assert_( t([123])==123)
        assert_( t((123,))==123)
        assert_( t(array(123))==123)
        assert_( t(array([123]))==123)
        assert_( t(array([[123]]))==123)
        assert_( t(array([123], 'b'))==123)
        assert_( t(array([123], 'h'))==123)
        assert_( t(array([123], 'i'))==123)
        assert_( t(array([123], 'l'))==123)
        assert_( t(array([123], 'B'))==123)
        assert_( t(array([123], 'f'))==123)
        assert_( t(array([123], 'd'))==123)

        #assert_raises(ValueError, t, array([123],'S3'))
        assert_raises(ValueError, t, 'abc')

        assert_raises(IndexError, t, [])
        assert_raises(IndexError, t, ())

        assert_raises(Exception, t, t)
        assert_raises(Exception, t, {})

        if t.__doc__.split()[0] in ['t8', 's8']:
            assert_raises(OverflowError, t, 100000000000000000000000)
            assert_raises(OverflowError, t, 10000000011111111111111.23)
开发者ID:7924102,项目名称:numpy,代码行数:31,代码来源:test_return_integer.py


示例3: test_r1array

 def test_r1array(self):
     """ Test to make sure equivalent Travis O's r1array function
     """
     assert_(atleast_1d(3).shape == (1,))
     assert_(atleast_1d(3j).shape == (1,))
     assert_(atleast_1d(long(3)).shape == (1,))
     assert_(atleast_1d(3.0).shape == (1,))
     assert_(atleast_1d([[2, 3], [4, 5]]).shape == (2, 2))
开发者ID:8ballbb,项目名称:ProjectRothar,代码行数:8,代码来源:test_shape_base.py


示例4: test_shares_memory_api

def test_shares_memory_api():
    x = np.zeros([4, 5, 6], dtype=np.int8)

    assert_equal(np.shares_memory(x, x), True)
    assert_equal(np.shares_memory(x, x.copy()), False)

    a = x[:,::2,::3]
    b = x[:,::3,::2]
    assert_equal(np.shares_memory(a, b), True)
    assert_equal(np.shares_memory(a, b, max_work=None), True)
    assert_raises(np.TooHardError, np.shares_memory, a, b, max_work=1)
    assert_raises(np.TooHardError, np.shares_memory, a, b, max_work=long(1))
开发者ID:Jengel1,项目名称:SunriseSunsetTimeFinder,代码行数:12,代码来源:test_mem_overlap.py


示例5: check_function

    def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ['t0', 't8', 's0', 's8']:
            err = 1e-5
        else:
            err = 0.0
        assert_( abs(t(234j)-234.0j)<=err)
        assert_( abs(t(234.6)-234.6)<=err)
        assert_( abs(t(long(234))-234.0)<=err)
        assert_( abs(t(234.6+3j)-(234.6+3j))<=err)
        #assert_( abs(t('234')-234.)<=err)
        #assert_( abs(t('234.6')-234.6)<=err)
        assert_( abs(t(-234)+234.)<=err)
        assert_( abs(t([234])-234.)<=err)
        assert_( abs(t((234,))-234.)<=err)
        assert_( abs(t(array(234))-234.)<=err)
        assert_( abs(t(array(23+4j, 'F'))-(23+4j))<=err)
        assert_( abs(t(array([234]))-234.)<=err)
        assert_( abs(t(array([[234]]))-234.)<=err)
        assert_( abs(t(array([234], 'b'))+22.)<=err)
        assert_( abs(t(array([234], 'h'))-234.)<=err)
        assert_( abs(t(array([234], 'i'))-234.)<=err)
        assert_( abs(t(array([234], 'l'))-234.)<=err)
        assert_( abs(t(array([234], 'q'))-234.)<=err)
        assert_( abs(t(array([234], 'f'))-234.)<=err)
        assert_( abs(t(array([234], 'd'))-234.)<=err)
        assert_( abs(t(array([234+3j], 'F'))-(234+3j))<=err)
        assert_( abs(t(array([234], 'D'))-234.)<=err)

        #assert_raises(TypeError, t, array([234], 'a1'))
        assert_raises(TypeError, t, 'abc')

        assert_raises(IndexError, t, [])
        assert_raises(IndexError, t, ())

        assert_raises(TypeError, t, t)
        assert_raises(TypeError, t, {})

        try:
            r = t(10**400)
            assert_( repr(r) in ['(inf+0j)', '(Infinity+0j)'], repr(r))
        except OverflowError:
            pass
开发者ID:7924102,项目名称:numpy,代码行数:43,代码来源:test_return_complex.py


示例6: check_function

    def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ["t0", "t8", "s0", "s8"]:
            err = 1e-5
        else:
            err = 0.0
        assert_(abs(t(234j) - 234.0j) <= err)
        assert_(abs(t(234.6) - 234.6) <= err)
        assert_(abs(t(long(234)) - 234.0) <= err)
        assert_(abs(t(234.6 + 3j) - (234.6 + 3j)) <= err)
        # assert_( abs(t('234')-234.)<=err)
        # assert_( abs(t('234.6')-234.6)<=err)
        assert_(abs(t(-234) + 234.0) <= err)
        assert_(abs(t([234]) - 234.0) <= err)
        assert_(abs(t((234,)) - 234.0) <= err)
        assert_(abs(t(array(234)) - 234.0) <= err)
        assert_(abs(t(array(23 + 4j, "F")) - (23 + 4j)) <= err)
        assert_(abs(t(array([234])) - 234.0) <= err)
        assert_(abs(t(array([[234]])) - 234.0) <= err)
        assert_(abs(t(array([234], "b")) + 22.0) <= err)
        assert_(abs(t(array([234], "h")) - 234.0) <= err)
        assert_(abs(t(array([234], "i")) - 234.0) <= err)
        assert_(abs(t(array([234], "l")) - 234.0) <= err)
        assert_(abs(t(array([234], "q")) - 234.0) <= err)
        assert_(abs(t(array([234], "f")) - 234.0) <= err)
        assert_(abs(t(array([234], "d")) - 234.0) <= err)
        assert_(abs(t(array([234 + 3j], "F")) - (234 + 3j)) <= err)
        assert_(abs(t(array([234], "D")) - 234.0) <= err)

        # assert_raises(TypeError, t, array([234], 'a1'))
        assert_raises(TypeError, t, "abc")

        assert_raises(IndexError, t, [])
        assert_raises(IndexError, t, ())

        assert_raises(TypeError, t, t)
        assert_raises(TypeError, t, {})

        try:
            r = t(10 ** 400)
            assert_(repr(r) in ["(inf+0j)", "(Infinity+0j)"], repr(r))
        except OverflowError:
            pass
开发者ID:Root-shady,项目名称:opencv,代码行数:43,代码来源:test_return_complex.py


示例7: check_function

 def check_function(self, t):
     assert_( t(True)==1, repr(t(True)))
     assert_( t(False)==0, repr(t(False)))
     assert_( t(0)==0)
     assert_( t(None)==0)
     assert_( t(0.0)==0)
     assert_( t(0j)==0)
     assert_( t(1j)==1)
     assert_( t(234)==1)
     assert_( t(234.6)==1)
     assert_( t(long(234))==1)
     assert_( t(234.6+3j)==1)
     assert_( t('234')==1)
     assert_( t('aaa')==1)
     assert_( t('')==0)
     assert_( t([])==0)
     assert_( t(())==0)
     assert_( t({})==0)
     assert_( t(t)==1)
     assert_( t(-234)==1)
     assert_( t(10**100)==1)
     assert_( t([234])==1)
     assert_( t((234,))==1)
     assert_( t(array(234))==1)
     assert_( t(array([234]))==1)
     assert_( t(array([[234]]))==1)
     assert_( t(array([234], 'b'))==1)
     assert_( t(array([234], 'h'))==1)
     assert_( t(array([234], 'i'))==1)
     assert_( t(array([234], 'l'))==1)
     assert_( t(array([234], 'f'))==1)
     assert_( t(array([234], 'd'))==1)
     assert_( t(array([234+3j], 'F'))==1)
     assert_( t(array([234], 'D'))==1)
     assert_( t(array(0))==0)
     assert_( t(array([0]))==0)
     assert_( t(array([[0]]))==0)
     assert_( t(array([0j]))==0)
     assert_( t(array([1]))==1)
     assert_raises(ValueError, t, array([0, 0]))
开发者ID:7924102,项目名称:numpy,代码行数:40,代码来源:test_return_logical.py


示例8: check_function

    def check_function(self, t):
        if t.__doc__.split()[0] in ['t0', 't4', 's0', 's4']:
            err = 1e-5
        else:
            err = 0.0
        assert_(abs(t(234) - 234.0) <= err)
        assert_(abs(t(234.6) - 234.6) <= err)
        assert_(abs(t(long(234)) - 234.0) <= err)
        assert_(abs(t('234') - 234) <= err)
        assert_(abs(t('234.6') - 234.6) <= err)
        assert_(abs(t(-234) + 234) <= err)
        assert_(abs(t([234]) - 234) <= err)
        assert_(abs(t((234,)) - 234.) <= err)
        assert_(abs(t(array(234)) - 234.) <= err)
        assert_(abs(t(array([234])) - 234.) <= err)
        assert_(abs(t(array([[234]])) - 234.) <= err)
        assert_(abs(t(array([234], 'b')) + 22) <= err)
        assert_(abs(t(array([234], 'h')) - 234.) <= err)
        assert_(abs(t(array([234], 'i')) - 234.) <= err)
        assert_(abs(t(array([234], 'l')) - 234.) <= err)
        assert_(abs(t(array([234], 'B')) - 234.) <= err)
        assert_(abs(t(array([234], 'f')) - 234.) <= err)
        assert_(abs(t(array([234], 'd')) - 234.) <= err)
        if t.__doc__.split()[0] in ['t0', 't4', 's0', 's4']:
            assert_(t(1e200) == t(1e300))  # inf

        #assert_raises(ValueError, t, array([234], 'S1'))
        assert_raises(ValueError, t, 'abc')

        assert_raises(IndexError, t, [])
        assert_raises(IndexError, t, ())

        assert_raises(Exception, t, t)
        assert_raises(Exception, t, {})

        try:
            r = t(10 ** 400)
            assert_(repr(r) in ['inf', 'Infinity'], repr(r))
        except OverflowError:
            pass
开发者ID:Jengel1,项目名称:SunriseSunsetTimeFinder,代码行数:40,代码来源:test_return_real.py


示例9: test_permutation_longs

 def test_permutation_longs(self):
     np.random.seed(1234)
     a = np.random.permutation(12)
     np.random.seed(1234)
     b = np.random.permutation(long(12))
     assert_array_equal(a, b)
开发者ID:Razin-Tailor,项目名称:ChatterBot,代码行数:6,代码来源:test_regression.py


示例10: __new__

    def __new__(subtype, filename, dtype=uint8, mode='r+', offset=0,
                shape=None, order='C'):
        # Import here to minimize 'import numpy' overhead
        import mmap
        import os.path
        try:
            mode = mode_equivalents[mode]
        except KeyError:
            if mode not in valid_filemodes:
                raise ValueError("mode must be one of %s" %
                                 (valid_filemodes + list(mode_equivalents.keys())))

        if hasattr(filename, 'read'):
            fid = filename
            own_file = False
        elif is_pathlib_path(filename):
            fid = filename.open((mode == 'c' and 'r' or mode)+'b')
            own_file = True
        else:
            fid = open(filename, (mode == 'c' and 'r' or mode)+'b')
            own_file = True

        if (mode == 'w+') and shape is None:
            raise ValueError("shape must be given")

        fid.seek(0, 2)
        flen = fid.tell()
        descr = dtypedescr(dtype)
        _dbytes = descr.itemsize

        if shape is None:
            bytes = flen - offset
            if (bytes % _dbytes):
                fid.close()
                raise ValueError("Size of available data is not a "
                        "multiple of the data-type size.")
            size = bytes // _dbytes
            shape = (size,)
        else:
            if not isinstance(shape, tuple):
                shape = (shape,)
            size = 1
            for k in shape:
                size *= k

        bytes = long(offset + size*_dbytes)

        if mode == 'w+' or (mode == 'r+' and flen < bytes):
            fid.seek(bytes - 1, 0)
            fid.write(np.compat.asbytes('\0'))
            fid.flush()

        if mode == 'c':
            acc = mmap.ACCESS_COPY
        elif mode == 'r':
            acc = mmap.ACCESS_READ
        else:
            acc = mmap.ACCESS_WRITE

        start = offset - offset % mmap.ALLOCATIONGRANULARITY
        bytes -= start
        offset -= start
        mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=start)

        self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm,
            offset=offset, order=order)
        self._mmap = mm
        self.offset = offset
        self.mode = mode

        if isinstance(filename, basestring):
            self.filename = os.path.abspath(filename)
        elif is_pathlib_path(filename):
            self.filename = filename.resolve()
        # py3 returns int for TemporaryFile().name
        elif (hasattr(filename, "name") and
              isinstance(filename.name, basestring)):
            self.filename = os.path.abspath(filename.name)
        # same as memmap copies (e.g. memmap + 1)
        else:
            self.filename = None

        if own_file:
            fid.close()

        return self
开发者ID:SylvainCorlay,项目名称:numpy,代码行数:86,代码来源:memmap.py


示例11: __new__

    def __new__(subtype, filename, dtype=uint8, mode='r+', offset=0,
                shape=None, order='C'):
        # Import here to minimize 'import numpy' overhead
        import mmap
        import os.path
        try:
            mode = mode_equivalents[mode]
        except KeyError:
            if mode not in valid_filemodes:
                raise ValueError("mode must be one of %s" %
                                 (valid_filemodes + list(mode_equivalents.keys())))

        if mode == 'w+' and shape is None:
            raise ValueError("shape must be given")

        if hasattr(filename, 'read'):
            f_ctx = contextlib_nullcontext(filename)
        else:
            f_ctx = open(os_fspath(filename), ('r' if mode == 'c' else mode)+'b')

        with f_ctx as fid:
            fid.seek(0, 2)
            flen = fid.tell()
            descr = dtypedescr(dtype)
            _dbytes = descr.itemsize

            if shape is None:
                bytes = flen - offset
                if bytes % _dbytes:
                    raise ValueError("Size of available data is not a "
                            "multiple of the data-type size.")
                size = bytes // _dbytes
                shape = (size,)
            else:
                if not isinstance(shape, tuple):
                    shape = (shape,)
                size = np.intp(1)  # avoid default choice of np.int_, which might overflow
                for k in shape:
                    size *= k

            bytes = long(offset + size*_dbytes)

            if mode == 'w+' or (mode == 'r+' and flen < bytes):
                fid.seek(bytes - 1, 0)
                fid.write(b'\0')
                fid.flush()

            if mode == 'c':
                acc = mmap.ACCESS_COPY
            elif mode == 'r':
                acc = mmap.ACCESS_READ
            else:
                acc = mmap.ACCESS_WRITE

            start = offset - offset % mmap.ALLOCATIONGRANULARITY
            bytes -= start
            array_offset = offset - start
            mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=start)

            self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm,
                                   offset=array_offset, order=order)
            self._mmap = mm
            self.offset = offset
            self.mode = mode

            if is_pathlib_path(filename):
                # special case - if we were constructed with a pathlib.path,
                # then filename is a path object, not a string
                self.filename = filename.resolve()
            elif hasattr(fid, "name") and isinstance(fid.name, basestring):
                # py3 returns int for TemporaryFile().name
                self.filename = os.path.abspath(fid.name)
            # same as memmap copies (e.g. memmap + 1)
            else:
                self.filename = None

        return self
开发者ID:gabriekq,项目名称:Text-pic-Mendonca,代码行数:77,代码来源:memmap.py


示例12: test_permutation_longs

 def test_permutation_longs(self):
     mt19937.seed(1234)
     a = mt19937.permutation(12)
     mt19937.seed(1234)
     b = mt19937.permutation(long(12))
     assert_array_equal(a, b)
开发者ID:afvincent,项目名称:ng-numpy-randomstate,代码行数:6,代码来源:test_numpy_mt19937_regressions.py



注:本文中的numpy.compat.long函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python compat.open_latin1函数代码示例发布时间:2022-05-27
下一篇:
Python compat.isfileobj函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap