当前位置: 首页>>代码示例>>Python>>正文


Python compat.long方法代码示例

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


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

示例1: test_truediv

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import long [as 别名]
def test_truediv(Poly):
    # true division is valid only if the denominator is a Number and
    # not a python bool.
    p1 = Poly([1,2,3])
    p2 = p1 * 5

    for stype in np.ScalarType:
        if not issubclass(stype, Number) or issubclass(stype, bool):
            continue
        s = stype(5)
        assert_poly_almost_equal(op.truediv(p2, s), p1)
        assert_raises(TypeError, op.truediv, s, p2)
    for stype in (int, long, float):
        s = stype(5)
        assert_poly_almost_equal(op.truediv(p2, s), p1)
        assert_raises(TypeError, op.truediv, s, p2)
    for stype in [complex]:
        s = stype(5, 0)
        assert_poly_almost_equal(op.truediv(p2, s), p1)
        assert_raises(TypeError, op.truediv, s, p2)
    for s in [tuple(), list(), dict(), bool(), np.array([1])]:
        assert_raises(TypeError, op.truediv, p2, s)
        assert_raises(TypeError, op.truediv, s, p2)
    for ptype in classes:
        assert_raises(TypeError, op.truediv, p2, ptype(1)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:test_classes.py

示例2: test_object_array_self_reference

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import long [as 别名]
def test_object_array_self_reference(self):
        # Object arrays with references to themselves can cause problems
        a = np.array(0, dtype=object)
        a[()] = a
        assert_raises(TypeError, int, a)
        assert_raises(TypeError, long, a)
        assert_raises(TypeError, float, a)
        assert_raises(TypeError, oct, a)
        assert_raises(TypeError, hex, a)

        # Test the same for a circular reference.
        b = np.array(a, dtype=object)
        a[()] = b
        assert_raises(TypeError, int, a)
        # Numpy has no tp_traverse currently, so circular references
        # cannot be detected. So resolve it:
        a[()] = 0

        # This was causing a to become like the above
        a = np.array(0, dtype=object)
        a[...] += 1
        assert_equal(a, 1) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:24,代码来源:test_regression.py

示例3: check_truediv

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import long [as 别名]
def check_truediv(Poly):
    # true division is valid only if the denominator is a Number and
    # not a python bool.
    p1 = Poly([1,2,3])
    p2 = p1 * 5

    for stype in np.ScalarType:
        if not issubclass(stype, Number) or issubclass(stype, bool):
            continue
        s = stype(5)
        assert_poly_almost_equal(op.truediv(p2, s), p1)
        assert_raises(TypeError, op.truediv, s, p2)
    for stype in (int, long, float):
        s = stype(5)
        assert_poly_almost_equal(op.truediv(p2, s), p1)
        assert_raises(TypeError, op.truediv, s, p2)
    for stype in [complex]:
        s = stype(5, 0)
        assert_poly_almost_equal(op.truediv(p2, s), p1)
        assert_raises(TypeError, op.truediv, s, p2)
    for s in [tuple(), list(), dict(), bool(), np.array([1])]:
        assert_raises(TypeError, op.truediv, p2, s)
        assert_raises(TypeError, op.truediv, s, p2)
    for ptype in classes:
        assert_raises(TypeError, op.truediv, p2, ptype(1)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:27,代码来源:test_classes.py

示例4: put

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import long [as 别名]
def put(array, indices, values, axis=0, clipmode=RAISE):
    if not isinstance(array, np.ndarray):
        raise TypeError("put only works on subclass of ndarray")
    work = asarray(array)
    if axis == 0:
        if array.ndim == 1:
            work.put(indices, values, clipmode)
        else:
            work[indices] = values
    elif isinstance(axis, (int, long, np.integer)):
        work = work.swapaxes(0, axis)
        work[indices] = values
        work = work.swapaxes(0, axis)
    else:
        def_axes = list(range(work.ndim))
        for x in axis:
            def_axes.remove(x)
        axis = list(axis)+def_axes
        work = work.transpose(axis)
        work[indices] = values
        work = work.transpose(axis) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:23,代码来源:functions.py

示例5: take

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import long [as 别名]
def take(array, indices, axis=0, outarr=None, clipmode=RAISE):
    array = np.asarray(array)
    if isinstance(axis, (int, long, np.integer)):
        res = array.take(indices, axis, outarr, clipmode)
        if outarr is None:
            return res
        return
    else:
        def_axes = list(range(array.ndim))
        for x in axis:
            def_axes.remove(x)
        axis = list(axis) + def_axes
        work = array.transpose(axis)
        res = work[indices]
        if outarr is None:
            return res
        outarr[...] = res
        return 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:20,代码来源:functions.py

示例6: __long__

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import long [as 别名]
def __long__(self):
        return self._scalarfunc(long) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:4,代码来源:user_array.py

示例7: __getitem__

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import long [as 别名]
def __getitem__(self, index):
        """
        Return a new arrayterator.

        """
        # Fix index, handling ellipsis and incomplete slices.
        if not isinstance(index, tuple):
            index = (index,)
        fixed = []
        length, dims = len(index), self.ndim
        for slice_ in index:
            if slice_ is Ellipsis:
                fixed.extend([slice(None)] * (dims-length+1))
                length = len(fixed)
            elif isinstance(slice_, (int, long)):
                fixed.append(slice(slice_, slice_+1, 1))
            else:
                fixed.append(slice_)
        index = tuple(fixed)
        if len(index) < dims:
            index += (slice(None),) * (dims-len(index))

        # Return a new arrayterator object.
        out = self.__class__(self.var, self.buf_size)
        for i, (start, stop, step, slice_) in enumerate(
                zip(self.start, self.stop, self.step, index)):
            out.start[i] = start + (slice_.start or 0)
            out.step[i] = step * (slice_.step or 1)
            out.stop[i] = start + (slice_.stop or stop-start)
            out.stop[i] = min(stop, out.stop[i])
        return out 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:33,代码来源:arrayterator.py

示例8: _check_inverse_of_slicing

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import long [as 别名]
def _check_inverse_of_slicing(self, indices):
        a_del = delete(self.a, indices)
        nd_a_del = delete(self.nd_a, indices, axis=1)
        msg = 'Delete failed for obj: %r' % indices
        # NOTE: The cast should be removed after warning phase for bools
        if not isinstance(indices, (slice, int, long, np.integer)):
            indices = np.asarray(indices, dtype=np.intp)
            indices = indices[(indices >= 0) & (indices < 5)]
        assert_array_equal(setxor1d(a_del, self.a[indices, ]), self.a,
                           err_msg=msg)
        xor = setxor1d(nd_a_del[0,:, 0], self.nd_a[0, indices, 0])
        assert_array_equal(xor, self.nd_a[0,:, 0], err_msg=msg) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:test_function_base.py

示例9: test_basic

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import long [as 别名]
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:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_type_check.py

示例10: check_function

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import long [as 别名]
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:Frank-qlu,项目名称:recruit,代码行数:33,代码来源:test_return_integer.py

示例11: check_function

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import long [as 别名]
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:Frank-qlu,项目名称:recruit,代码行数:42,代码来源:test_return_logical.py

示例12: test_permutation_longs

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import long [as 别名]
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:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_regression.py

示例13: test_shares_memory_api

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import long [as 别名]
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:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:test_mem_overlap.py

示例14: test_r1array

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import long [as 别名]
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:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_shape_base.py

示例15: test_array_side_effect

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import long [as 别名]
def test_array_side_effect(self):
        # The second use of itemsize was throwing an exception because in
        # ctors.c, discover_itemsize was calling PyObject_Length without
        # checking the return code.  This failed to get the length of the
        # number 2, and the exception hung around until something checked
        # PyErr_Occurred() and returned an error.
        assert_equal(np.dtype('S10').itemsize, 10)
        np.array([['abc', 2], ['long   ', '0123456789']], dtype=np.string_)
        assert_equal(np.dtype('S10').itemsize, 10) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_regression.py


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