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


Python numpy.base_repr方法代碼示例

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


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

示例1: totalistic_rule

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import base_repr [as 別名]
def totalistic_rule(neighbourhood, k, rule):
    """
    The totalistic rule as described in NKS. The average color is mapped to a whole number in [0, k - 1].
    The rule number is in base 10, but interpreted in base k. For a 1-dimensional cellular automaton, there are
    3k - 2 possible average colors in the 3-cell neighbourhood. There are n(k - 1) + 1 possible average colors for a 
    k-color cellular automaton with an n-cell neighbourhood.
    :param neighbourhood: a k-color array of any size
    :param k: the number of colors in this cellular automaton, where only 2 <= k <= 36 is supported
    :param rule: the k-color cellular automaton rule number in base 10, interpreted in base k
    :return: the result, a number from 0 to k - 1, of applying the given rule on the given state
    """
    # e.g. np.base_repr(777, base=3) -> '1001210'; the zfill pads the string with zeroes: '1'.zfill(3) -> '001'
    #   Bases greater than 36 not handled in base_repr.
    n = neighbourhood.size
    rule_string = np.base_repr(rule, base=k).zfill(n*(k - 1) + 1)
    if len(rule_string) > n*(k - 1) + 1:
        raise Exception("rule number out of range")
    neighbourhood_sum = np.sum(neighbourhood)
    # the rightmost element of the rule is for the average color 0, in NKS convention
    return int(rule_string[n*(k - 1) - neighbourhood_sum], k) 
開發者ID:lantunes,項目名稱:cellpylib,代碼行數:22,代碼來源:ca_functions.py

示例2: test_base3

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import base_repr [as 別名]
def test_base3(self):
        assert_equal(np.base_repr(3**5, 3), '100000') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:4,代碼來源:test_numeric.py

示例3: test_positive

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import base_repr [as 別名]
def test_positive(self):
        assert_equal(np.base_repr(12, 10), '12')
        assert_equal(np.base_repr(12, 10, 4), '000012')
        assert_equal(np.base_repr(12, 4), '30')
        assert_equal(np.base_repr(3731624803700888, 36), '10QR0ROFCEW') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:7,代碼來源:test_numeric.py

示例4: test_negative

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import base_repr [as 別名]
def test_negative(self):
        assert_equal(np.base_repr(-12, 10), '-12')
        assert_equal(np.base_repr(-12, 10, 4), '-000012')
        assert_equal(np.base_repr(-12, 4), '-30') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:6,代碼來源:test_numeric.py

示例5: test_base_range

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import base_repr [as 別名]
def test_base_range(self):
        with assert_raises(ValueError):
            np.base_repr(1, 1)
        with assert_raises(ValueError):
            np.base_repr(1, 37) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:7,代碼來源:test_numeric.py

示例6: base_repr

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import base_repr [as 別名]
def base_repr(number, base=2, padding=0):  # NOQA (needed to avoid redefinition of `number`)
    """Return a string representation of a number in the given base system.

    .. seealso:: :func:`numpy.base_repr`
    """
    return numpy.base_repr(number, base, padding)


# -----------------------------------------------------------------------------
# Linear algebra
# ----------------------------------------------------------------------------- 
開發者ID:cupy,項目名稱:cupy,代碼行數:13,代碼來源:__init__.py


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