当前位置: 首页>>代码示例>>Python>>正文


Python bitarray.bitarray方法代码示例

本文整理汇总了Python中bitarray.bitarray方法的典型用法代码示例。如果您正苦于以下问题:Python bitarray.bitarray方法的具体用法?Python bitarray.bitarray怎么用?Python bitarray.bitarray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bitarray的用法示例。


在下文中一共展示了bitarray.bitarray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: decode_full_lc

# 需要导入模块: import bitarray [as 别名]
# 或者: from bitarray import bitarray [as 别名]
def decode_full_lc(_data):
    binlc = bitarray(endian='big')   
    binlc.extend([_data[136],_data[121],_data[106],_data[91], _data[76], _data[61], _data[46], _data[31]])
    binlc.extend([_data[152],_data[137],_data[122],_data[107],_data[92], _data[77], _data[62], _data[47], _data[32], _data[17], _data[2]  ])
    binlc.extend([_data[123],_data[108],_data[93], _data[78], _data[63], _data[48], _data[33], _data[18], _data[3],  _data[184],_data[169]])
    binlc.extend([_data[94], _data[79], _data[64], _data[49], _data[34], _data[19], _data[4],  _data[185],_data[170],_data[155],_data[140]])
    binlc.extend([_data[65], _data[50], _data[35], _data[20], _data[5],  _data[186],_data[171],_data[156],_data[141],_data[126],_data[111]])
    binlc.extend([_data[36], _data[21], _data[6],  _data[187],_data[172],_data[157],_data[142],_data[127],_data[112],_data[97], _data[82] ])
    binlc.extend([_data[7],  _data[188],_data[173],_data[158],_data[143],_data[128],_data[113],_data[98], _data[83]])
    '''
    This is the rest of the Full LC data -- the RS1293 FEC that we don't need
     _data[68],_data[53],_data[174],_data[159],_data[144],_data[129],_data[114],_data[99],_data[84],_data[69],_data[54],_data[39],
    _data[24],_data[145],_data[130],_data[115],_data[100],_data[85],_data[70],_data[55],_data[40],_data[25],_data[10],_data[191]
    '''
    return binlc

#------------------------------------------------------------------------------
# BPTC(196,96) Encoding Routings
#------------------------------------------------------------------------------ 
开发者ID:n0mjs710,项目名称:dmr_utils,代码行数:21,代码来源:bptc.py

示例2: __init__

# 需要导入模块: import bitarray [as 别名]
# 或者: from bitarray import bitarray [as 别名]
def __init__(self, container):
        USBDevice.__init__(self, container)
        self.data = bitarray(48, endian='little')
        self.data.setall(False)
        self.start_time = datetime.datetime.now()
        self.isNunchukCalibrated = False
        self.center_x = 1
        self.x_neg_range = 1
        self.x_pos_range = 1

        self.center_y = 1
        self.y_neg_range = 1
        self.y_pos_range = 1

        self.previousAccX = 0
        self.previousAccY = 0 
开发者ID:Frazew,项目名称:PythonUSBIP,代码行数:18,代码来源:hid_wiimote.py

示例3: get_huffman_codebook

# 需要导入模块: import bitarray [as 别名]
# 或者: from bitarray import bitarray [as 别名]
def get_huffman_codebook(symb2freq):
    """
    Huffman encode the given dict mapping symbols to weights
    :param symb2freq: dict, {symbol: frequency}
    :return:
        dict, value(float/int) : code(bitarray)
    """
    heap = [[wt, [sym, ""]] for sym, wt in symb2freq.items()]
    heapify(heap)
    while len(heap) > 1:
        lo = heappop(heap)
        hi = heappop(heap)
        for pair in lo[1:]:
            pair[1] = '0' + pair[1]
        for pair in hi[1:]:
            pair[1] = '1' + pair[1]
        heappush(heap, [lo[0] + hi[0]] + lo[1:] + hi[1:])
    codebook = sorted(heappop(heap)[1:], key=lambda p: (len(p[-1]), p))
    return dict(map(lambda x: (x[0], bitarray(x[1])), codebook)) 
开发者ID:synxlin,项目名称:nn-compression,代码行数:21,代码来源:encode.py

示例4: __read__

# 需要导入模块: import bitarray [as 别名]
# 或者: from bitarray import bitarray [as 别名]
def __read__(self, fname, m, n):
        if not fname.endswith('.bed'):
            raise ValueError('.bed filename must end in .bed')

        fh = open(fname, 'rb')
        magicNumber = ba.bitarray(endian="little")
        magicNumber.fromfile(fh, 2)
        bedMode = ba.bitarray(endian="little")
        bedMode.fromfile(fh, 1)
        e = (4 - n % 4) if n % 4 != 0 else 0
        nru = n + e
        self.nru = nru
        # check magic number
        if magicNumber != ba.bitarray('0011011011011000'):
            raise IOError("Magic number from Plink .bed file not recognized")

        if bedMode != ba.bitarray('10000000'):
            raise IOError("Plink .bed file must be in default SNP-major mode")

        # check file length
        self.geno = ba.bitarray(endian="little")
        self.geno.fromfile(fh)
        self.__test_length__(self.geno, self.m, self.nru)
        return (self.nru, self.geno) 
开发者ID:JonJala,项目名称:mtag,代码行数:26,代码来源:ldscore.py

示例5: decode_emblc

# 需要导入模块: import bitarray [as 别名]
# 或者: from bitarray import bitarray [as 别名]
def decode_emblc(_elc):
    
    _binlc = bitarray(endian='big')
    _binlc.extend([_elc[0],_elc[8], _elc[16],_elc[24],_elc[32],_elc[40],_elc[48],_elc[56],_elc[64],_elc[72] ,_elc[80]])
    _binlc.extend([_elc[1],_elc[9], _elc[17],_elc[25],_elc[33],_elc[41],_elc[49],_elc[57],_elc[65],_elc[73] ,_elc[81]])
    _binlc.extend([_elc[2],_elc[10],_elc[18],_elc[26],_elc[34],_elc[42],_elc[50],_elc[58],_elc[66],_elc[74]])
    _binlc.extend([_elc[3],_elc[11],_elc[19],_elc[27],_elc[35],_elc[43],_elc[51],_elc[59],_elc[67],_elc[75]])
    _binlc.extend([_elc[4],_elc[12],_elc[20],_elc[28],_elc[36],_elc[44],_elc[52],_elc[60],_elc[68],_elc[76]])
    _binlc.extend([_elc[5],_elc[13],_elc[21],_elc[29],_elc[37],_elc[45],_elc[53],_elc[61],_elc[69],_elc[77]])
    _binlc.extend([_elc[6],_elc[14],_elc[22],_elc[30],_elc[38],_elc[46],_elc[54],_elc[62],_elc[70],_elc[78]])
    
    return(_binlc.tobytes())

#------------------------------------------------------------------------------
# BPTC Embedded LC Encoding Routines
#------------------------------------------------------------------------------


# Accepts 12 byte LC header + 5-bit checksum, converts to binary and builts out the BPTC
# encoded result with hamming(16,11,4) and parity. 
开发者ID:n0mjs710,项目名称:dmr_utils,代码行数:22,代码来源:bptc.py

示例6: _compute_coverage_scores

# 需要导入模块: import bitarray [as 别名]
# 或者: from bitarray import bitarray [as 别名]
def _compute_coverage_scores(self):
        # Get total number of ORIGIN elements FIXME: (not KW, etc)
        (leafs, _) = self._provenance.get_leafs_and_heads()
        total_number = len(leafs)

        i = 0
        for origin in leafs:
            # Assign index to original values
            self._origin_values_coverage[origin] = i
            i += 1

        for el in self.data:
            # initialize coverage set to False
            coverage_set = bitarray(len(leafs))
            coverage_set.setall(False)
            # Get covered elements
            elements = self.why(el)
            for element_covered in elements:
                idx = self._origin_values_coverage[element_covered]
                coverage_set[idx] = True
            coverage = float(len(elements)) / float(total_number)
            self._rank_data[el]['coverage_score'] = (coverage, coverage_set) 
开发者ID:mitdbg,项目名称:aurum-datadiscovery,代码行数:24,代码来源:apiutils.py

示例7: transpose_low_mem

# 需要导入模块: import bitarray [as 别名]
# 或者: from bitarray import bitarray [as 别名]
def transpose_low_mem(bitarrays):
    logger.info("Using slow, low memory transpose")
    # Takes a list of bitarrays and returns the transpose as a list of
    # bitarrays
    x = len(bitarrays)
    y = bitarrays[0].length()
    logger.info("BFM dims %i %i" % (x, y))

    tbitarrays = []
    for ii in range(y):
        ba = bitarray(x)
        ba.setall(False)
        tbitarrays.append(ba)
    for i in range(x):
        for j in range(y):
            tbitarrays[j][i] = bitarrays[i][j]
    return tbitarrays 
开发者ID:Phelimb,项目名称:BIGSI,代码行数:19,代码来源:transpose.py

示例8: test_get_set

# 需要导入模块: import bitarray [as 别名]
# 或者: from bitarray import bitarray [as 别名]
def test_get_set():
    rows = [
        bitarray("001"),
        bitarray("001"),
        bitarray("111"),
        bitarray("001"),
        bitarray("111"),
    ] * 5
    for storage in get_storages():
        storage.delete_all()
        bm = BitMatrix.create(storage, rows, len(rows), len(rows[0]))
        bm.set_rows(range(25), rows)
        assert list(bm.get_rows(range(3))) == rows[:3]
        assert bm.get_column(0) == bitarray("00101" * 5)
        assert bm.get_column(2) == bitarray("1" * 25)
        assert list(bm.get_columns([0, 2])) == [
            bitarray("00101" * 5),
            bitarray("1" * 25),
        ] 
开发者ID:Phelimb,项目名称:BIGSI,代码行数:21,代码来源:test_bitmatrix.py

示例9: test_get_insert_column

# 需要导入模块: import bitarray [as 别名]
# 或者: from bitarray import bitarray [as 别名]
def test_get_insert_column():
    rows = [
        bitarray("001"),
        bitarray("001"),
        bitarray("111"),
        bitarray("001"),
        bitarray("111"),
    ] * 5
    for storage in get_storages():
        storage.delete_all()
        bm = BitMatrix.create(storage, rows, len(rows), len(rows[0]))
        assert bm.get_column(0) == bitarray("00101" * 5)
        bm.insert_column(bitarray("1" * 25), 0)
        assert bm.get_column(0) == bitarray("1" * 25)

        assert bm.get_row(1) == bitarray("101")
        bm.insert_column(bitarray("1" * 25), 3)
        assert bm.get_column(3) == bitarray("1" * 25)
        assert bm.get_row(1) == bitarray("1011") 
开发者ID:Phelimb,项目名称:BIGSI,代码行数:21,代码来源:test_bitmatrix.py

示例10: test_bloom_cmd

# 需要导入模块: import bitarray [as 别名]
# 或者: from bitarray import bitarray [as 别名]
def test_bloom_cmd():
    for config_file in CONFIG_FILES:
        f = "/tmp/test_kmers.bloom"
        response = hug.test.post(
            bigsi.__main__,
            "bloom",
            {
                "config": config_file,
                "ctx": "bigsi/tests/data/test_kmers.ctx",
                "outfile": f,
            },
        )
        a = bitarray()
        with open("/tmp/test_kmers.bloom", "rb") as inf:
            a.fromfile(inf)
        assert sum(a) > 0
        os.remove("/tmp/test_kmers.bloom") 
开发者ID:Phelimb,项目名称:BIGSI,代码行数:19,代码来源:test_cli.py

示例11: program_global_reg

# 需要导入模块: import bitarray [as 别名]
# 或者: from bitarray import bitarray [as 别名]
def program_global_reg(self):
        """
        Send the global register to the chip.

        Loads the values of self['GLOBAL_REG'] onto the chip.
        Includes enabling the clock, and loading the Control (CTR)
        and DAC shadow registers.

        """

        self._clear_strobes()

        gr_size = len(self['GLOBAL_REG'][:])  # get the size
        self['SEQ']['SHIFT_IN'][0:gr_size] = self['GLOBAL_REG'][:]  # this will be shifted out
        self['SEQ']['GLOBAL_SHIFT_EN'][0:gr_size] = bitarray(gr_size * '1')  # this is to enable clock
        self['SEQ']['GLOBAL_CTR_LD'][gr_size + 1:gr_size + 2] = bitarray("1")  # load signals
        self['SEQ']['GLOBAL_DAC_LD'][gr_size + 1:gr_size + 2] = bitarray("1")

        # Execute the program (write bits to output pins)
        # + 1 extra 0 bit so that everything ends on LOW instead of HIGH
        self._run_seq(gr_size + 3) 
开发者ID:SiLab-Bonn,项目名称:basil,代码行数:23,代码来源:lx9.py

示例12: program_pixel_reg

# 需要导入模块: import bitarray [as 别名]
# 或者: from bitarray import bitarray [as 别名]
def program_pixel_reg(self, enable_receiver=True):
        """
        Send the pixel register to the chip and store the output.

        Loads the values of self['PIXEL_REG'] onto the chip.
        Includes enabling the clock, and loading the Control (CTR)
        and DAC shadow registers.

        if(enable_receiver), stores the output (by byte) in
        self['DATA'], retrievable via `chip['DATA'].get_data()`.

        """

        self._clear_strobes()

        # enable receiver it work only if pixel register is enabled/clocked
        self['PIXEL_RX'].set_en(enable_receiver)

        px_size = len(self['PIXEL_REG'][:])  # get the size
        self['SEQ']['SHIFT_IN'][0:px_size] = self['PIXEL_REG'][:]  # this will be shifted out
        self['SEQ']['PIXEL_SHIFT_EN'][0:px_size] = bitarray(px_size * '1')  # this is to enable clock

        print('px_size = {}'.format(px_size))

        self._run_seq(px_size + 1)  # add 1 bit more so there is 0 at the end other way will stay high 
开发者ID:SiLab-Bonn,项目名称:basil,代码行数:27,代码来源:lx9.py

示例13: program_pixel_reg

# 需要导入模块: import bitarray [as 别名]
# 或者: from bitarray import bitarray [as 别名]
def program_pixel_reg(self, enable_receiver=True):
        """
        Send the pixel register to the chip and store the output.

        Loads the values of self['PIXEL_REG'] onto the chip.
        Includes enabling the clock, and loading the Control (CTR)
        and DAC shadow registers.

        if(enable_receiver), stores the output (by byte) in
        self['DATA'], retrievable via `chip['DATA'].get_data()`.

        """

        self._clear_strobes()

        # enable receiver it work only if pixel register is enabled/clocked
        self['PIXEL_RX'].set_en(enable_receiver)

        px_size = len(self['PIXEL_REG'][:])  # get the size
        self['SEQ']['SHIFT_IN'][0:px_size] = self['PIXEL_REG'][:]  # this will be shifted out
        self['SEQ']['PIXEL_SHIFT_EN'][0:px_size] = bitarray(px_size * '1')  # this is to enable clock

        self._run_seq(px_size + 1)  # add 1 bit more so there is 0 at the end other way will stay high 
开发者ID:SiLab-Bonn,项目名称:basil,代码行数:25,代码来源:pixel.py

示例14: test_simple

# 需要导入模块: import bitarray [as 别名]
# 或者: from bitarray import bitarray [as 别名]
def test_simple(self):
        input_arr = bitarray('10' * 64)

        self.chip['PIXEL_REG'][:] = input_arr
        self.chip['PIXEL_REG'][0] = 0
        self.chip.program_pixel_reg()

        ret = self.chip['DATA'].get_data()

        data0 = ret.astype(np.uint8)
        data1 = np.right_shift(ret, 8).astype(np.uint8)
        data = np.reshape(np.vstack((data1, data0)), -1, order='F')
        bdata = np.unpackbits(data)

        input_arr[0] = 0

        self.assertEqual(input_arr.tolist(), bdata.tolist()) 
开发者ID:SiLab-Bonn,项目名称:basil,代码行数:19,代码来源:test_Sim.py

示例15: write

# 需要导入模块: import bitarray [as 别名]
# 或者: from bitarray import bitarray [as 别名]
def write(self, size=-1):
        if size == -1:
            size = self._conf["seq_size"]

        bv = bitarray(self._conf["seq_width"] * size)
        for i in range(size):
            for track in self._conf['tracks']:
                bit = 0
                if self._conf["seq_width"] >= 8:
                    bit = i * self._conf["seq_width"] + self._conf["seq_width"] - 1 - track['position']
                elif self._conf["seq_width"] == 4:
                    if i % 2 == 0:
                        bit = (i + 1) * self._conf["seq_width"] + self._conf["seq_width"] - 1 - track['position']
                    else:
                        bit = (i - 1) * self._conf["seq_width"] + self._conf["seq_width"] - 1 - track['position']
                else:
                    raise NotImplementedError("To be implemented.")
                bv[bit] = self._tracks[track['name']][i]

        ba = utils.bitarray_to_byte_array(bv)
        ba = ba[::-1]
        # TODO: this probably has to be done different way
        self._drv.set_data(ba) 
开发者ID:SiLab-Bonn,项目名称:basil,代码行数:25,代码来源:TrackRegister.py


注:本文中的bitarray.bitarray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。