python类bitwise_or()的实例源码

evaluate.py 文件源码 项目:lsun-room 作者: leVirve 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def labelcolormap(N=256):

    def bitget(byteval, idx):
        return ((byteval & (1 << idx)) != 0)

    cmap = np.zeros((N, 3))
    for i in range(0, N):
        id = i
        r, g, b = 0, 0, 0
        for j in range(0, 8):
            r = np.bitwise_or(r, (bitget(id, 0) << 7-j))
            g = np.bitwise_or(g, (bitget(id, 1) << 7-j))
            b = np.bitwise_or(b, (bitget(id, 2) << 7-j))
            id = (id >> 3)
        cmap[i, 0] = r
        cmap[i, 1] = g
        cmap[i, 2] = b
    cmap = cmap.astype(np.float32) / 255
    return cmap
importers.py 文件源码 项目:deep-prior 作者: moberweger 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def loadDepthMap(self,filename):
        """
        Read a depth-map
        :param filename: file name to load
        :return: image data of depth image
        """

        img = Image.open(filename)
        # top 8 bits of depth are packed into green channel and lower 8 bits into blue
        assert len(img.getbands()) == 3
        r, g, b = img.split()
        r = np.asarray(r, np.int32)
        g = np.asarray(g, np.int32)
        b = np.asarray(b, np.int32)
        dpt = np.bitwise_or(np.left_shift(g, 8), b)
        imgdata = np.asarray(dpt, np.float32)

        return imgdata
test_ufunc.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_NotImplemented_not_returned(self):
        # See gh-5964 and gh-2091. Some of these functions are not operator
        # related and were fixed for other reasons in the past.
        binary_funcs = [
            np.power, np.add, np.subtract, np.multiply, np.divide,
            np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or,
            np.bitwise_xor, np.left_shift, np.right_shift, np.fmax,
            np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2,
            np.logical_and, np.logical_or, np.logical_xor, np.maximum,
            np.minimum, np.mod
            ]

        # These functions still return NotImplemented. Will be fixed in
        # future.
        # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal]

        a = np.array('1')
        b = 1
        for f in binary_funcs:
            assert_raises(TypeError, f, a, b)
utils.py 文件源码 项目:labelme 作者: wkentaro 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def label_colormap(N=256):

    def bitget(byteval, idx):
        return ((byteval & (1 << idx)) != 0)

    cmap = np.zeros((N, 3))
    for i in range(0, N):
        id = i
        r, g, b = 0, 0, 0
        for j in range(0, 8):
            r = np.bitwise_or(r, (bitget(id, 0) << 7-j))
            g = np.bitwise_or(g, (bitget(id, 1) << 7-j))
            b = np.bitwise_or(b, (bitget(id, 2) << 7-j))
            id = (id >> 3)
        cmap[i, 0] = r
        cmap[i, 1] = g
        cmap[i, 2] = b
    cmap = cmap.astype(np.float32) / 255
    return cmap
test_ufunc.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_NotImplemented_not_returned(self):
        # See gh-5964 and gh-2091. Some of these functions are not operator
        # related and were fixed for other reasons in the past.
        binary_funcs = [
            np.power, np.add, np.subtract, np.multiply, np.divide,
            np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or,
            np.bitwise_xor, np.left_shift, np.right_shift, np.fmax,
            np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2,
            np.logical_and, np.logical_or, np.logical_xor, np.maximum,
            np.minimum, np.mod
            ]

        # These functions still return NotImplemented. Will be fixed in
        # future.
        # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal]

        a = np.array('1')
        b = 1
        for f in binary_funcs:
            assert_raises(TypeError, f, a, b)
test_ufunc.py 文件源码 项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda 作者: SignalMedia 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_NotImplemented_not_returned(self):
        # See gh-5964 and gh-2091. Some of these functions are not operator
        # related and were fixed for other reasons in the past.
        binary_funcs = [
            np.power, np.add, np.subtract, np.multiply, np.divide,
            np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or,
            np.bitwise_xor, np.left_shift, np.right_shift, np.fmax,
            np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2,
            np.logical_and, np.logical_or, np.logical_xor, np.maximum,
            np.minimum, np.mod
            ]

        # These functions still return NotImplemented. Will be fixed in
        # future.
        # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal]

        a = np.array('1')
        b = 1
        for f in binary_funcs:
            assert_raises(TypeError, f, a, b)
test_ufunc.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_NotImplemented_not_returned(self):
        # See gh-5964 and gh-2091. Some of these functions are not operator
        # related and were fixed for other reasons in the past.
        binary_funcs = [
            np.power, np.add, np.subtract, np.multiply, np.divide,
            np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or,
            np.bitwise_xor, np.left_shift, np.right_shift, np.fmax,
            np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2,
            np.logical_and, np.logical_or, np.logical_xor, np.maximum,
            np.minimum, np.mod
            ]

        # These functions still return NotImplemented. Will be fixed in
        # future.
        # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal]

        a = np.array('1')
        b = 1
        for f in binary_funcs:
            assert_raises(TypeError, f, a, b)
importers.py 文件源码 项目:deep-prior-pp 作者: moberweger 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def loadDepthMap(self, filename):
        """
        Read a depth-map
        :param filename: file name to load
        :return: image data of depth image
        """

        img = Image.open(filename)
        # top 8 bits of depth are packed into green channel and lower 8 bits into blue
        assert len(img.getbands()) == 3
        r, g, b = img.split()
        r = np.asarray(r, np.int32)
        g = np.asarray(g, np.int32)
        b = np.asarray(b, np.int32)
        dpt = np.bitwise_or(np.left_shift(g, 8), b)
        imgdata = np.asarray(dpt, np.float32)

        return imgdata
test_ufunc.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_NotImplemented_not_returned(self):
        # See gh-5964 and gh-2091. Some of these functions are not operator
        # related and were fixed for other reasons in the past.
        binary_funcs = [
            np.power, np.add, np.subtract, np.multiply, np.divide,
            np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or,
            np.bitwise_xor, np.left_shift, np.right_shift, np.fmax,
            np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2,
            np.logical_and, np.logical_or, np.logical_xor, np.maximum,
            np.minimum, np.mod
            ]

        # These functions still return NotImplemented. Will be fixed in
        # future.
        # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal]

        a = np.array('1')
        b = 1
        for f in binary_funcs:
            assert_raises(TypeError, f, a, b)
utils.py 文件源码 项目:Semantic-Segmentation-using-Adversarial-Networks 作者: oyam 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def labelcolormap(N=256):
    cmap = np.zeros((N, 3))
    for i in range(0, N):
        id = i
        r, g, b = 0, 0, 0
        for j in range(0, 8):
            r = np.bitwise_or(r, (bitget(id, 0) << 7-j))
            g = np.bitwise_or(g, (bitget(id, 1) << 7-j))
            b = np.bitwise_or(b, (bitget(id, 2) << 7-j))
            id = (id >> 3)
        cmap[i, 0] = r
        cmap[i, 1] = g
        cmap[i, 2] = b
    cmap = cmap.astype(np.float32) / 255
    return cmap


# -----------------------------------------------------------------------------
# Evaluation
# -----------------------------------------------------------------------------
test_umath.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_values(self):
        for dt in self.bitwise_types:
            zeros = np.array([0], dtype=dt)
            ones = np.array([-1], dtype=dt)
            msg = "dt = '%s'" % dt.char

            assert_equal(np.bitwise_not(zeros), ones, err_msg=msg)
            assert_equal(np.bitwise_not(ones), zeros, err_msg=msg)

            assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg)
            assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg)
            assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg)
            assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg)

            assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg)
            assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg)
            assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg)
            assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg)

            assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg)
            assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg)
            assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg)
            assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg)
elemwise.py 文件源码 项目:Theano-Deep-learning 作者: GeekLiB 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def set_ufunc(self, scalar_op):
        # This is probably a speed up of the implementation
        if isinstance(scalar_op, theano.scalar.basic.Add):
            self.ufunc = numpy.add
        elif isinstance(scalar_op, theano.scalar.basic.Mul):
            self.ufunc = numpy.multiply
        elif isinstance(scalar_op, theano.scalar.basic.Maximum):
            self.ufunc = numpy.maximum
        elif isinstance(scalar_op, theano.scalar.basic.Minimum):
            self.ufunc = numpy.minimum
        elif isinstance(scalar_op, theano.scalar.basic.AND):
            self.ufunc = numpy.bitwise_and
        elif isinstance(scalar_op, theano.scalar.basic.OR):
            self.ufunc = numpy.bitwise_or
        elif isinstance(scalar_op, theano.scalar.basic.XOR):
            self.ufunc = numpy.bitwise_xor
        else:
            self.ufunc = numpy.frompyfunc(scalar_op.impl, 2, 1)
test_ufunc.py 文件源码 项目:Alfred 作者: jkachhadia 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_NotImplemented_not_returned(self):
        # See gh-5964 and gh-2091. Some of these functions are not operator
        # related and were fixed for other reasons in the past.
        binary_funcs = [
            np.power, np.add, np.subtract, np.multiply, np.divide,
            np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or,
            np.bitwise_xor, np.left_shift, np.right_shift, np.fmax,
            np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2,
            np.logical_and, np.logical_or, np.logical_xor, np.maximum,
            np.minimum, np.mod
            ]

        # These functions still return NotImplemented. Will be fixed in
        # future.
        # bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal]

        a = np.array('1')
        b = 1
        for f in binary_funcs:
            assert_raises(TypeError, f, a, b)
test_umath.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_truth_table_bitwise(self):
        arg1 = [False, False, True, True]
        arg2 = [False, True, False, True]

        out = [False, True, True, True]
        assert_equal(np.bitwise_or(arg1, arg2), out)

        out = [False, False, False, True]
        assert_equal(np.bitwise_and(arg1, arg2), out)

        out = [False, True, True, False]
        assert_equal(np.bitwise_xor(arg1, arg2), out)
fusion.py 文件源码 项目:cupy 作者: cupy 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def __or__(self, other):
        return bitwise_or(self, other)
fusion.py 文件源码 项目:cupy 作者: cupy 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __ior__(self, other):
        return bitwise_or(self, other, self)
fusion.py 文件源码 项目:cupy 作者: cupy 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __ror__(self, other):
        return bitwise_or(other, self)
utils.py 文件源码 项目:fcn 作者: wkentaro 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def label_colormap(N=256):
    cmap = np.zeros((N, 3))
    for i in six.moves.range(0, N):
        id = i
        r, g, b = 0, 0, 0
        for j in six.moves.range(0, 8):
            r = np.bitwise_or(r, (bitget(id, 0) << 7 - j))
            g = np.bitwise_or(g, (bitget(id, 1) << 7 - j))
            b = np.bitwise_or(b, (bitget(id, 2) << 7 - j))
            id = (id >> 3)
        cmap[i, 0] = r
        cmap[i, 1] = g
        cmap[i, 2] = b
    cmap = cmap.astype(np.float32) / 255
    return cmap
keysight.py 文件源码 项目:Auspex 作者: BBN-Q 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def create_binary_wf_data(wf, sync_mkr=0, samp_mkr=0, vertical_resolution=12):
        """Given numpy arrays of waveform and marker data convert to binary format.
        Assumes waveform data is np.float in range -1 to 1 and marker data can be cast to bool
        Binary format is waveform in MSB and and markers in LSB
        waveform       sync_mkr samp_mkr
        15 downto 4/2     1      0
        """
        #cast the waveform to integers
        if not((vertical_resolution == 12) or (vertical_resolution == 14)):
            raise ValueError("vertical resolution must be 12 or 14 bits")

        #convert waveform to integers
        scale_factor = 2**(vertical_resolution-1)
        bin_data = np.int16((scale_factor-1)*np.array(wf))

        #clip if necessary
        if np.max(bin_data) > scale_factor-1 or np.min(bin_data) < -scale_factor:
            warnings.warn("Clipping waveform. Max value: {:d} Min value: {:d}. Scale factor: {:d}.".format(np.max(bin_data), np.min(bin_data),scale_factor))
            bin_data = np.clip(bin_data, -scale_factor, scale_factor-1)

        # bin_data = bin_data.byteswap()
        #shift up to the MSB
        bin_data = np.left_shift(bin_data, 4 if vertical_resolution == 12 else 2)

        #add in the marker bits
        bin_data = np.bitwise_or(bin_data, np.bitwise_or(np.left_shift(np.bitwise_and(sync_mkr, 0x1), 1), np.bitwise_and(samp_mkr, 0x1)))

        return bin_data
mask.py 文件源码 项目:chainer-fcis 作者: knorth55 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def get_mask_overlap(mask1, mask2):
    intersect = np.bitwise_and(mask1, mask2).sum()
    union = np.bitwise_or(mask1, mask2).sum()
    return 1.0 * intersect / union
keypoint.py 文件源码 项目:AlphaLogo 作者: gigaflw 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def _find_DoG_extrema(self, DoG):
        # TODO: sample ?
        ext = []
        for octave in DoG:
            _, rows, cols = octave.shape
            # assert octave.shape = (<layers>(=s+2), <rows>, <columns>)

            ##########################
            # time ?
            ##########################
            peeled = [octave[ind1, ind2, ind3] for ind1, ind2, ind3 in
                      product(*[[slice(1, -1), slice(2, None), slice(None, -2)]]*3)]
            center_block = peeled[0]  # octave[1:-1,1:-1,1:-1], the center part
            neighbor_blocks = peeled[1:]  # neighbors in 26 directions in 3-D DoG space with offset 1
            is_extreme = \
                np.bitwise_or(center_block > (np.max(neighbor_blocks, axis=0)),
                              center_block < (np.min(neighbor_blocks, axis=0)))
            # assert is_extreme.shape = (s, rows-2, columns-2)

            ext_coord = np.array(
                list(product(*[range(1, i-1) for i in octave.shape]))).reshape([x-2 for x in octave.shape]+[-1])
            assert ext_coord.shape[:-1] == is_extreme.shape

            ext_coord = ext_coord[is_extreme].astype(np.float)
            print("%d key point candidates found" % ext_coord.shape[0])
            # assert ext_coord.shape = (<number of key points>, 3)
            ext_coord /= [1, rows, cols]   # convert row, col coord to relative
            ext_coord[:, 0] = get_sigma_by_layer(ext_coord[:, 0])

            ext.extend(list(ext_coord))

            # filters
            # for layer, row, col in ext_coord:
            # nb = octave[layer-1:layer+2, row-1:row+2, col-1:col+2]  # 3x3x3 neighbor
            # x_hat, d_x_hat = self._fit_extremum(nb)
            # if
            # TODO: if x[i] > 0.5, do it recursivey
            # print(x_hat, d_x_hat)

        return ext
test_umath.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_truth_table_bitwise(self):
        arg1 = [False, False, True, True]
        arg2 = [False, True, False, True]

        out = [False, True, True, True]
        assert_equal(np.bitwise_or(arg1, arg2), out)

        out = [False, False, False, True]
        assert_equal(np.bitwise_and(arg1, arg2), out)

        out = [False, True, True, False]
        assert_equal(np.bitwise_xor(arg1, arg2), out)
yt_array.py 文件源码 项目:yt 作者: yt-project 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def __ior__(self, other):
            np.bitwise_or(self, other, out=self)
            return self
sdf.py 文件源码 项目:yt 作者: yt-project 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def spread_bitsv(ival, level):
    res = np.zeros_like(ival, dtype='int64')
    for i in range(level):
        ares = np.bitwise_and(ival, 1<<i) << (i*2)
        np.bitwise_or(res, ares, res)
    return res
sdf.py 文件源码 项目:yt 作者: yt-project 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def get_keyv(iarr, level):
    i1, i2, i3 = (v.astype("int64") for v in iarr)
    i1 = spread_bitsv(i1, level)
    i2 = spread_bitsv(i2, level) << 1
    i3 = spread_bitsv(i3, level) << 2
    np.bitwise_or(i1, i2, i1)
    np.bitwise_or(i1, i3, i1)
    return i1
word_bool_distance.py 文件源码 项目:alfpy 作者: aziele 项目源码 文件源码 阅读 54 收藏 0 点赞 0 评论 0
def pwdist_jaccard(self, seq1idx, seq2idx):
        """Compute the Jaccard-Needham dissimilarity
        between two boolean 1-D arrays.

        Returns:
            distance value (double)

        """
        u = self[seq1idx]
        v = self[seq2idx]
        dist = (np.double(np.bitwise_and((u != v),
                np.bitwise_or(u != 0, v != 0)).sum()) /
                np.double(np.bitwise_or(u != 0, v != 0).sum()))
        return dist
depth.py 文件源码 项目:crossingNet 作者: melonwan 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def loadNYU(self, path):
        img = Image.open(path)
        if len(img.getbands()) != 3:
            raise ValueError('NYU input should be with 3 channel')
        r, g, b = img.split()
        r = np.asarray(r,np.int32)
        g = np.asarray(g,np.int32)
        b = np.asarray(b,np.int32)
        dpt = np.bitwise_or(np.left_shift(g,8),b)
        self.dmData = np.asarray(dpt, np.float32)
        return self.dmData
test_umath.py 文件源码 项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda 作者: SignalMedia 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_truth_table_bitwise(self):
        arg1 = [False, False, True, True]
        arg2 = [False, True, False, True]

        out = [False, True, True, True]
        assert_equal(np.bitwise_or(arg1, arg2), out)

        out = [False, False, False, True]
        assert_equal(np.bitwise_and(arg1, arg2), out)

        out = [False, True, True, False]
        assert_equal(np.bitwise_xor(arg1, arg2), out)
test_umath.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_truth_table_bitwise(self):
        arg1 = [False, False, True, True]
        arg2 = [False, True, False, True]

        out = [False, True, True, True]
        assert_equal(np.bitwise_or(arg1, arg2), out)

        out = [False, False, False, True]
        assert_equal(np.bitwise_and(arg1, arg2), out)

        out = [False, True, True, False]
        assert_equal(np.bitwise_xor(arg1, arg2), out)
test_umath.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_truth_table_bitwise(self):
        arg1 = [False, False, True, True]
        arg2 = [False, True, False, True]

        out = [False, True, True, True]
        assert_equal(np.bitwise_or(arg1, arg2), out)

        out = [False, False, False, True]
        assert_equal(np.bitwise_and(arg1, arg2), out)

        out = [False, True, True, False]
        assert_equal(np.bitwise_xor(arg1, arg2), out)


问题


面经


文章

微信
公众号

扫码关注公众号