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


Python numpy.ulonglong方法代碼示例

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


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

示例1: _unsigned_subtract

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ulonglong [as 別名]
def _unsigned_subtract(a, b):
    """
    Subtract two values where a >= b, and produce an unsigned result

    This is needed when finding the difference between the upper and lower
    bound of an int16 histogram
    """
    # coerce to a single type
    signed_to_unsigned = {
        np.byte: np.ubyte,
        np.short: np.ushort,
        np.intc: np.uintc,
        np.int_: np.uint,
        np.longlong: np.ulonglong
    }
    dt = np.result_type(a, b)
    try:
        dt = signed_to_unsigned[dt.type]
    except KeyError:
        return np.subtract(a, b, dtype=dt)
    else:
        # we know the inputs are integers, and we are deliberately casting
        # signed to unsigned
        return np.subtract(a, b, casting='unsafe', dtype=dt) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:26,代碼來源:histograms.py

示例2: _unsigned_subtract

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ulonglong [as 別名]
def _unsigned_subtract(a, b):
    """
    Subtract two values where a >= b, and produce an unsigned result

    This is needed when finding the difference between the upper and lower
    bound of an int16 histogram
    """
    # coerce to a single type
    signed_to_unsigned = {
        np.byte: np.ubyte,
        np.short: np.ushort,
        np.intc: np.uintc,
        np.int_: np.uint,
        np.longlong: np.ulonglong
    }
    dt = np.result_type(a, b)
    try:
        dt = signed_to_unsigned[dt.type]
    except KeyError:  # pragma: no cover
        return np.subtract(a, b, dtype=dt)
    else:
        # we know the inputs are integers, and we are deliberately casting
        # signed to unsigned
        return np.subtract(a, b, casting='unsafe', dtype=dt) 
開發者ID:mars-project,項目名稱:mars,代碼行數:26,代碼來源:histogram.py

示例3: scatter_add

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ulonglong [as 別名]
def scatter_add(a, slices, b):
    """Adds given values to specified elements of an array.

    This function adds ``b`` to the specified elements of the copy of
    ``a``, and returns the copy.
    The value of the original ``a`` is not changed.

    Args:
        a (:class:`~chainer.Variable` or :ref:`ndarray`): A variable.
        slices (int, slice, Ellipsis, None, integer array-like, boolean\
        array-like or tuple of them):
            It is an integer, a slice, an ellipsis,
            a numpy.newaxis, an integer array-like, a boolean array-like
            or tuple of them.
        b (:class:`~chainer.Variable` or :ref:`ndarray`):
            A variable that is scatter added to ``a``.
            Its shape has to equal ``a[slices]`` because broadcasting
            of variables is not supported.

    Returns:
        A :class:`~chainer.Variable` object which is the result of
        scatter addition.

    .. note::

        It only supports types that are supported by CUDA's atomicAdd when
        an integer array is included in ``slices``.
        The supported types are ``numpy.float32``, ``numpy.int32``,
        ``numpy.uint32``, ``numpy.uint64`` and ``numpy.ulonglong``.

    .. note::

        It does not support ``slices`` that contains multiple boolean arrays.

    .. seealso::
        :func:`numpy.add.at` and
        :func:`cupyx.scatter_add`.

    """
    y, = ScatterAdd(slices).apply((a, b))
    return y 
開發者ID:chainer,項目名稱:chainer,代碼行數:43,代碼來源:scatter_add.py

示例4: test_numpy

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ulonglong [as 別名]
def test_numpy(self):
        """NumPy objects get serialized to readable JSON."""
        l = [
            np.float32(12.5),
            np.float64(2.0),
            np.float16(0.5),
            np.bool(True),
            np.bool(False),
            np.bool_(True),
            np.unicode_("hello"),
            np.byte(12),
            np.short(12),
            np.intc(-13),
            np.int_(0),
            np.longlong(100),
            np.intp(7),
            np.ubyte(12),
            np.ushort(12),
            np.uintc(13),
            np.ulonglong(100),
            np.uintp(7),
            np.int8(1),
            np.int16(3),
            np.int32(4),
            np.int64(5),
            np.uint8(1),
            np.uint16(3),
            np.uint32(4),
            np.uint64(5),
        ]
        l2 = [l, np.array([1, 2, 3])]
        roundtripped = loads(dumps(l2, cls=EliotJSONEncoder))
        self.assertEqual([l, [1, 2, 3]], roundtripped) 
開發者ID:itamarst,項目名稱:eliot,代碼行數:35,代碼來源:test_json.py

示例5: test_return_arrcrt_zeros

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ulonglong [as 別名]
def test_return_arrcrt_zeros(a, b, c):
    d = np.zeros(3)
    d[:] = 2
    d[0] = 1
    return d

# TODO: fix for np.ulonglong, np.longlong and uint64 
開發者ID:jakeret,項目名稱:hope,代碼行數:9,代碼來源:test_return.py

示例6: test_return_scalar

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ulonglong [as 別名]
def test_return_scalar(dtype):
    def fkt(a): return a
    ao, ah = random(dtype, [])
    ro, rh = fkt(ao), hope.jit(fkt)(ah)
    assert check(ro, rh)

# TODO: fix for np.ulonglong, np.longlong and uint64 
開發者ID:jakeret,項目名稱:hope,代碼行數:9,代碼來源:test_return.py

示例7: test_return_arrayscalar

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ulonglong [as 別名]
def test_return_arrayscalar(dtype):
    def fkt(a): return a[2]
    ao, ah = random(dtype, [10])
    ro, rh = fkt(ao), hope.jit(fkt)(ah)
    assert check(ro, rh)

# TODO: fix for np.ulonglong, np.longlong and uint64 
開發者ID:jakeret,項目名稱:hope,代碼行數:9,代碼來源:test_return.py

示例8: test_augmented_pow

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ulonglong [as 別名]
def test_augmented_pow(dtype, shape):
    def fkt(a, c): 
        c[:] **= a
    hfkt = hope.jit(fkt)
    (ao, ah), (co, ch) = random(np.uint8, shape), random(dtype, shape)
    if np.count_nonzero(ao == 0) > 0: ao[ao == 0] += 1
    if np.count_nonzero(ah == 0) > 0: ah[ah == 0] += 1
    if np.count_nonzero(co == 0) > 0: co[co == 0] += 1
    if np.count_nonzero(ch == 0) > 0: ch[ch == 0] += 1
    co, ch = np.copysign(np.sqrt(np.abs(co)), co).astype(dtype), np.copysign(np.sqrt(np.abs(ch)), ch).astype(dtype)
    ao, ah = np.power(np.abs(ao).astype(np.float64), 1. / co.astype(np.float64)).astype(dtype), np.power(np.abs(ah).astype(np.float64), 1. / ch.astype(np.float64)).astype(dtype)
    fkt(ao, co),  hfkt(ah, ch)
    assert check(co, ch)

# TODO: fix for np.ulonglong and uint64, std::power produce different results 
開發者ID:jakeret,項目名稱:hope,代碼行數:17,代碼來源:test_op_pow.py

示例9: get_item

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import ulonglong [as 別名]
def get_item(x, slices):
    """Extract elements from array with specified shape, axes and offsets.

    Args:
        x (:class:`~chainer.Variable` or :ref:`ndarray`):
            A variable to be sliced.
        slices (int, slice, Ellipsis, None, integer array-like, boolean\
        array-like or tuple of them):
            An object to specify the selection of elements.

    Returns:
        A :class:`~chainer.Variable` object which contains sliced array of
        ``x``.

    .. note::

        It only supports types that are supported by CUDA's atomicAdd when
        an integer array is included in ``slices``.
        The supported types are ``numpy.float32``, ``numpy.int32``,
        ``numpy.uint32``, ``numpy.uint64`` and ``numpy.ulonglong``.

    .. note::

        It does not support ``slices`` that contains multiple boolean arrays.

    .. note::

       See NumPy documentation for details of `indexing
       <https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html>`_.

    .. admonition:: Example

        >>> x = np.arange(12).reshape((2, 2, 3))
        >>> x
        array([[[ 0,  1,  2],
                [ 3,  4,  5]],
        <BLANKLINE>
               [[ 6,  7,  8],
                [ 9, 10, 11]]])
        >>> F.get_item(x, 0)
        variable([[0, 1, 2],
                  [3, 4, 5]])
        >>> F.get_item(x, (0, 0, slice(0, 2, 1)))  # equals x[0, 0, 0:2:1]
        variable([0, 1])
        >>> F.get_item(x, (Ellipsis, 2))  # equals x[..., 2]
        variable([[ 2,  5],
                  [ 8, 11]])
        >>> F.get_item(x, (1, np.newaxis, 1, 0))  # equals x[1, None, 1, 0]
        variable([9])

    """
    return GetItem(slices).apply((x,))[0] 
開發者ID:chainer,項目名稱:chainer,代碼行數:54,代碼來源:get_item.py


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