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


Python block.Block类代码示例

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


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

示例1: __init__

 def __init__(self, adjStats = string.ascii_letters + ' ', noisy = False):
   # Load it...
   if noisy: print 'Reading in ply2 corpus file...'
   data = read(os.path.join(os.path.dirname(__file__),'corpus.ply2'))
   
   # Convert contents into a list of blocks...
   self.blocks = []
   
   t_arr = data['element']['document']['text']
   a_arr = data['element']['document']['attribution']
   
   if noisy:
     print 'Creating blocks...'
   
   for i in xrange(t_arr.shape[0]):
     b = Block(t_arr[i], a_arr[i])
     self.blocks.append(b)
     
   # Construct all statistics - this gets complicated for reasons of efficiency...
   if noisy:
     print 'Collecting statistics...'
   
   self.counts = numpy.zeros(256, dtype=numpy.int32)
   self.adj = numpy.zeros((len(adjStats),len(adjStats)), dtype=numpy.int32)
   self.adj_index = adjStats
   
   for b in self.blocks:
     b.stats(self.counts, self.adj, self.adj_index)
开发者ID:eosbamsi,项目名称:helit,代码行数:28,代码来源:corpus.py

示例2: __init__

    def __init__(self, over, under):
        Top.__init__(self, find_bounding_box(over + under))

        from block import Block

        self.over = Block(over)
        self.under = Block(under)
开发者ID:matthieubulte,项目名称:math-recon,代码行数:7,代码来源:fraction.py

示例3: _block_real_name

 def _block_real_name(self):
     if type(self._block) is str:
         return Block.to_real_name(Block.from_full_name(self._block)[1])
     elif self._block is None:
         return None
     else:
         return self._block.real_name()
开发者ID:SmartDataProjects,项目名称:dynamo,代码行数:7,代码来源:lfile.py

示例4: compute_blocks

    def compute_blocks(self):
        """
            Compute the set of blocks that C infer
            return: Topologically sorted blocks T_c
        """

        timer_start('Compute blocks')

        T_c = list()
        T_unions = set()

        # iterate the combination sizes in reverse
        a = range(len(self.C)+1)[::-1]
        for i in a:
            choose = i
            for comb in combinations(self.C, choose):
                union = itemsets.union_of_itemsets(comb)

                if not union in T_unions:
                    T_unions.add(union)
                    T = Block()
                    T.union_of_itemsets = union
                    T.singletons = itemsets.singletons_of_itemsets(comb)
                    T.itemsets = set(comb)

                    T_c.append(T)

        timer_stop('Compute blocks')
        return T_c
开发者ID:AndersHqst,项目名称:PyMTV,代码行数:29,代码来源:model.py

示例5: __init__

class Game:

	def __init__( self, scr, loop ):

		self.scr = scr

		from block import Block
		self.block = Block( scr )

		from message import Messages
		self.msg = Messages( self.scr )

		self.loop = loop

		self.FPS = 60

		self.block( self, self.loop )

	def update( self ):

		lasttime = time.time(  )

		self.block.update(  )

		self.FPS = 1.0 / ( time.time(  ) - lasttime )

	def draw( self ):

		scr = self.scr
		scr.fill( ( 35, 35, 35 ) )

		self.block.draw(  )
		self.msg.message( round( self.FPS, 1 ), ( 10, 10 ) )
开发者ID:xhalo32,项目名称:advpy,代码行数:33,代码来源:game.py

示例6: __init__

 def __init__(self, size):
     """Initialize board:
        argument: size
     """
     self.size = size
     self.side = BLACK
     self.goban = {} #actual board
     self.init_hash()
     #Create and initialize board as empty size*size
     for pos in self.iterate_goban():
         #can't use set_goban method here, because goban doesn't yet really exists
         self.goban[pos] = EMPTY
         self.current_hash = self.current_hash ^ self.board_hash_values[EMPTY, pos]
     self.blocks = {} #blocks dictionary
     #Create and initialize one whole board empty block
     new_block = Block(EMPTY)
     for pos in self.iterate_goban():
         new_block.add_stone(pos)
     self.block_dict = {}
     self.add_block(new_block)
     self.chains = {}
     self.stone_count = {}
     for color in EMPTY+BLACK+WHITE:
         self.stone_count[color] = 0
     self.ko_flag = PASS_MOVE
     BoardAnalysis.__init__(self)
开发者ID:Aleum,项目名称:MiniGo,代码行数:26,代码来源:board.py

示例7: make_updated_block_for_site

def make_updated_block_for_site(transformation_matrix,
		                operators_to_add_to_block):
    """Make a new block for a list of operators.

    Takes a dictionary of operator names and matrices and makes a new
    block inserting in the `operators` block dictionary the result of
    transforming the matrices in the original dictionary accoring to the
    transformation matrix.

    You use this function everytime you want to create a new block by
    transforming the current operators to a truncated basis. 

    Parameters
    ----------
    transformation_matrix : a numpy array of ndim = 2.
        The transformation matrix coming from a (truncated) unitary
	transformation.
    operators_to_add_to_block : a dict of strings and numpy arrays of ndim = 2.
        The list of operators to transform.

    Returns
    -------
    result : a Block.
        A block with the new transformed operators.
    """
    cols_of_transformation_matrix = transformation_matrix.shape[1]
    result = Block(cols_of_transformation_matrix)
    for key in operators_to_add_to_block.keys():
	result.add_operator(key)
	result.operators[key] = transform_matrix(operators_to_add_to_block[key],
			                         transformation_matrix)
    return result
开发者ID:chanul13,项目名称:hubbard_dimer,代码行数:32,代码来源:system.py

示例8: parse

def parse(blockchain):
	print 'print Parsing Block Chain'
	counter = 0
	while True:
		print counter
		block = Block(blockchain)
		block.toString()
		counter+=1
开发者ID:instagibbs,项目名称:blocktools,代码行数:8,代码来源:sight.py

示例9: __init__

 def __init__(self, image_path, position, center, collider=None):
     Block.__init__(self, image_path, position, collider)
     self.center = center
     self.this_center = pygame.math.Vector2(self.position.x
                                            + self.animation.current_frame().get_width() / 2,
                                            self.position.y
                                            + self.animation.current_frame().get_height() / 2)
     self.distance = self.this_center - self.center
     self.type = Entity.TYPE_OBJECT_DYNAMIC
开发者ID:liam-mitchell,项目名称:seal-shark,代码行数:9,代码来源:rotatorblock.py

示例10: parse

def parse(file_name):
    '''function that takes a file name, and returns a list of blocks,
       instances of class Block.'''
    from block import Block
# open file, specified on command line
    block_file = open(file_name, 'r')
# compile the regular expressions to be used for performance reasons
    comment_pattern = re.compile(r'\s*#.*')
    block_start_pattern = re.compile(r'\s*begin\s+(\w+)')
    block_end_pattern = re.compile(r'\s*end\s+(\w+)')
# current_block holds an instance of Block for the block that is being
# parsed, its # value is None when outside a block, note that it doubles
# as state variable
    current_block = None
# list to hold the blocks
    blocks = []
    for line in block_file:
        # remove leading/triailing spaces, and comments (i.e., everything
        # following a '#'
        line = comment_pattern.sub('', line.strip())
# ignore blank lines
        if len(line) == 0:
            continue
# check for begin block
        match = block_start_pattern.match(line)
        if match is not None:
            # if current_block is not None, we are already in a block,
            # raise error
            if current_block is not None:
                raise ParseError(
                    'block {0} is not close when opening {1}'.format(
                        current_block.get_name(), match.group(1)))
# now in a block, so change state
            current_block = Block(match.group(1))
            continue
# check for end block
        match = block_end_pattern.match(line)
        if match is not None:
            # if the end block name is not the current block, raise error
            if match.group(1) != current_block.get_name():
                raise ParseError(
                    'block {0} is closed with {1}'.format(
                        match.group(1), current_block.get_name()))
# now out of a block, add current block to the list, and change state
            blocks.append(current_block)
            current_block = None
            continue
# if not in a block, ignore the line
        if current_block is None:
            continue
        else:
            # store block data
            current_block.add_data(line)
# close the file
    block_file.close()
    return blocks
开发者ID:bizatheo,项目名称:training-material,代码行数:56,代码来源:oo_fs_parser.py

示例11: split_marked_group

 def split_marked_group(self, block, mark):
     """move all stones with given mark to new block
        Return splitted group.
     """
     new_block = Block(block.color)
     for stone, value in block.stones.items():
         if value==mark:
             block.remove_stone(stone)
             new_block.add_stone(stone)
     return new_block
开发者ID:Aleum,项目名称:MiniGo,代码行数:10,代码来源:board.py

示例12: __init_blocks

 def __init_blocks(self):
     self.blocks = list()
     row_mid = len(self.piece[0])/2
     row_offset = self.__first_non_empty_row()
     for row in range(0, len(self.piece)):
         for col in range(0, len(self.piece[row])):
             block_symbol = self.piece[row][col]
             if block_symbol != '.':
                 block = Block(block_symbol)
                 block.move_to((col - row_mid, row - row_offset))
                 self.blocks.append(block)
开发者ID:Lateks,项目名称:Tetris,代码行数:11,代码来源:piece.py

示例13: new_next_block

def new_next_block():
    global next_block
    global next_block_pos
    new_type = random.choice(block_types)
    next_block = Block(new_type[0], new_type[1], [0, 0], board_width, board_height)
    width, height = next_block.get_size()
    width *= block_size
    height *= block_size
    x = next_block_surface[0] + next_block_surface[2] / 2 - width / 2
    y = next_block_surface[1] + next_block_surface[3] / 2 - height / 2
    next_block_pos = [x, y]
开发者ID:derheimel,项目名称:Tetris,代码行数:11,代码来源:tetris.py

示例14: polarArray

def polarArray(geom,numberOfCopies,totalAngle=2*pi,center=Point(0,0)):
    '''
    array geometric entity in a polar pattern
    '''
    b = Block()
    theta_step = totalAngle / numberOfCopies
    theta = 0.0
    for i in range(numberOfCopies):
        g = rotateAboutPoint(geom,center,theta)
        b.append(g)
        theta += theta_step
    return b
开发者ID:gfsmith,项目名称:gears,代码行数:12,代码来源:twod_operations.py

示例15: spawn_block

    def spawn_block(self):
        """
        Creates a new block with random starting position/random orientation.
        """
        block = Block()
        #block.position = (random.randint(0,GRID_WIDTH-1),block.position[1]) #uncomment here and comment below for randomly positioned blocks
        block.position = (GRID_WIDTH/2,block.position[1]) #spawn in middle of field
        for i in range(random.randint(0,3)): #random orientation
            block.rotate(True)

        self.block_count += 1
        return block
开发者ID:Andrew-Lucero,项目名称:tetris,代码行数:12,代码来源:tetris.py


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