本文整理汇总了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)
示例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)
示例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()
示例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
示例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 ) )
示例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)
示例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
示例8: parse
def parse(blockchain):
print 'print Parsing Block Chain'
counter = 0
while True:
print counter
block = Block(blockchain)
block.toString()
counter+=1
示例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
示例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
示例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
示例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)
示例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]
示例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
示例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