當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。