python类binary_repr()的实例源码

test_regression.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def test_binary_repr_0_width(self, level=rlevel):
        assert_equal(np.binary_repr(0, width=3), '000')
test_numeric.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def test_zero(self):
        assert_equal(np.binary_repr(0), '0')
test_numeric.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 44 收藏 0 点赞 0 评论 0
def test_large(self):
        assert_equal(np.binary_repr(10736848), '101000111101010011010000')
test_numeric.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 44 收藏 0 点赞 0 评论 0
def test_negative(self):
        assert_equal(np.binary_repr(-1), '-1')
        assert_equal(np.binary_repr(-1, width=8), '11111111')
grape_functions.py 文件源码 项目:quantum-optimal-control 作者: SchusterLab 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def Bin(a,N):
    a_bin = np.binary_repr(a)
    while len(a_bin) < N:
        a_bin = '0'+a_bin
    return a_bin
test_regression.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 49 收藏 0 点赞 0 评论 0
def test_binary_repr_0(self,level=rlevel):
        # Ticket #151
        assert_equal('0', np.binary_repr(0))
test_regression.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def test_binary_repr_0_width(self, level=rlevel):
        assert_equal(np.binary_repr(0, width=3), '000')
test_numeric.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def test_zero(self):
        assert_equal(np.binary_repr(0), '0')
test_numeric.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 45 收藏 0 点赞 0 评论 0
def test_large(self):
        assert_equal(np.binary_repr(10736848), '101000111101010011010000')
test_numeric.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_negative(self):
        assert_equal(np.binary_repr(-1), '-1')
        assert_equal(np.binary_repr(-1, width=8), '11111111')
test_regression.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def test_binary_repr_0(self, level=rlevel):
        # Ticket #151
        assert_equal('0', np.binary_repr(0))
test_regression.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_binary_repr_0_width(self, level=rlevel):
        assert_equal(np.binary_repr(0, width=3), '000')
test_numeric.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_zero(self):
        assert_equal(np.binary_repr(0), '0')
test_numeric.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_positive(self):
        assert_equal(np.binary_repr(10), '1010')
        assert_equal(np.binary_repr(12522),
                     '11000011101010')
        assert_equal(np.binary_repr(10736848),
                     '101000111101010011010000')
test_numeric.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def test_negative(self):
        assert_equal(np.binary_repr(-1), '-1')
        assert_equal(np.binary_repr(-10), '-1010')
        assert_equal(np.binary_repr(-12522),
                     '-11000011101010')
        assert_equal(np.binary_repr(-10736848),
                     '-101000111101010011010000')
test_deprecations.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def test_insufficient_width_positive(self):
        args = (10,)
        kwargs = {'width': 2}

        self.message = ("Insufficient bit width provided. This behavior "
                        "will raise an error in the future.")
        self.assert_deprecated(np.binary_repr, args=args, kwargs=kwargs)
test_deprecations.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_insufficient_width_negative(self):
        args = (-5,)
        kwargs = {'width': 2}

        self.message = ("Insufficient bit width provided. This behavior "
                        "will raise an error in the future.")
        self.assert_deprecated(np.binary_repr, args=args, kwargs=kwargs)
ParamBag.py 文件源码 项目:bnpy 作者: bnpy 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def _getAllowedShapes(self, shape):
        ''' Return set of allowed shapes that can be squeezed into given shape.

        Examples
        --------
        >>> PB = ParamBag() # fixing K,D doesn't matter
        >>> PB._getAllowedShapes(())
        set([()])
        >>> PB._getAllowedShapes((1,))
        set([(), (1,)])
        >>> aSet = PB._getAllowedShapes((23,))
        >>> sorted(aSet)
        [(23,)]
        >>> sorted(PB._getAllowedShapes((3,1)))
        [(3,), (3, 1)]
        >>> sorted(PB._getAllowedShapes((1,1)))
        [(), (1,), (1, 1)]
        '''
        assert isinstance(shape, tuple)
        allowedShapes = set()
        if len(shape) == 0:
            allowedShapes.add(tuple())
            return allowedShapes
        shapeVec = np.asarray(shape, dtype=np.int32)
        onesMask = shapeVec == 1
        keepMask = np.logical_not(onesMask)
        nOnes = sum(onesMask)
        for b in range(2**nOnes):
            bStr = np.binary_repr(b)
            bStr = '0' * (nOnes - len(bStr)) + bStr
            keepMask[onesMask] = np.asarray([int(x) > 0 for x in bStr])
            curShape = shapeVec[keepMask]
            allowedShapes.add(tuple(curShape))
        return allowedShapes
parametric.py 文件源码 项目:decoding_challenge_cortana_2016_3rd 作者: kingjr 项目源码 文件源码 阅读 43 收藏 0 点赞 0 评论 0
def _get_contrast_indices(effect_idx, n_factors):
    """Henson's factor coding, see num2binvec"""
    binrepr = np.binary_repr(effect_idx, n_factors)
    return np.array([int(i) for i in binrepr], dtype=int)
MarkovNetwork.py 文件源码 项目:MarkovNetwork 作者: rhiever 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def activate_network(self, num_activations=1):
        """Activates the Markov Network

        Parameters
        ----------
        num_activations: int (default: 1)
            The number of times the Markov Network should be activated

        Returns
        -------
        None

        """
        original_input_values = np.copy(self.states[:self.num_input_states])
        for _ in range(num_activations):
            for markov_gate, mg_input_ids, mg_output_ids in zip(self.markov_gates, self.markov_gate_input_ids, self.markov_gate_output_ids):
                # Determine the input values for this Markov Gate
                mg_input_values = self.states[mg_input_ids]
                mg_input_index = int(''.join([str(int(val)) for val in mg_input_values]), base=2)

                # Determine the corresponding output values for this Markov Gate
                roll = np.random.uniform()
                mg_output_index = np.where(markov_gate[mg_input_index, :] >= roll)[0][0]
                mg_output_values = np.array(list(np.binary_repr(mg_output_index, width=len(mg_output_ids))), dtype=np.uint8)
                self.states[mg_output_ids] = np.bitwise_or(self.states[mg_output_ids], mg_output_values)

            self.states[:self.num_input_states] = original_input_values


问题


面经


文章

微信
公众号

扫码关注公众号