本文整理汇总了Python中vector.Vector.is_zero方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.is_zero方法的具体用法?Python Vector.is_zero怎么用?Python Vector.is_zero使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vector.Vector
的用法示例。
在下文中一共展示了Vector.is_zero方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_matrix
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import is_zero [as 别名]
def make_matrix(vector_list):
'''
Make a matrix out of a list of vectors 'vector_list'
Just like make_vector in the vector module, this decides whether to instantiate the FullMatrix or SparseMatrix class
by using the is_zero method of the Vector class
'''
count = 0
for vector1 in vector_list:
vector_obj = Vector(vector1, zero_test = lambda x : (x == 0))
if(vector_obj.is_zero()==True):
count = count+1
if((count/len(vector_list))>DENSITY_THRESHOLD and len(vector_list)>SIZE_THRESHOLD):
i = 0
matrix_elmts = []
matrix_indices = []
while(i<len(vector_list)):
vector_obj1 = Vector(vector_list[i] , zero_test = lambda x : (x == 0))
if(vector_obj1.is_zero()==True):
matrix_elmts.append(vector_list[i])
matrix_indices.append(i)
i = i+1
else:
i = 0
matrix_elmts = []
while(i<len(vector_list)):
matrix_elmts.append(vector_list[i])
i = i+1
开发者ID:Amit-Tomar,项目名称:Parametrized-String-Matching-Implementation-for-Software-Plagiarism-Check,代码行数:29,代码来源:IMT2013031_matrix.py
示例2: __init__
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import is_zero [as 别名]
#.........这里部分代码省略.........
self.delta_position.set_magnitude(0.0)
self.delta_position.add(self.velocity)
self.delta_position.multiply(dt)
self.delta_x_vector.x=self.delta_position.x
self.delta_y_vector.y=self.delta_position.y
self.position_z += self.z_vector*dt
if self.facing_right and controls.left:
self.facing_right=False
self.blit_flags=Image.FLIPPED_H
elif not self.facing_right and controls.right:
self.facing_right=True
self.blit_flags=Image.NONE
self._update_state()
def draw(self, surface):
self.image.blit(self.animations[self.state].get_frame(), self.position.x, self.position.y+self.position_z, surface, self.blit_flags)
def _get_x_accel_vector( self, controls ):
self.x_accel_vector.set_magnitude(0)
if controls.up:
if controls.left:
self.x_accel_vector.x = self.accelerate_upper_left.x
elif controls.right:
self.x_accel_vector.x = self.accelerate_upper_right.x
elif controls.down:
if controls.left:
self.x_accel_vector.x = self.accelerate_lower_left.x
elif controls.right:
self.x_accel_vector.x = self.accelerate_lower_right.x
elif controls.left:
self.x_accel_vector.x=self.accelerate_left.x
elif controls.right:
self.x_accel_vector.x=self.accelerate_right.x
elif self.velocity.x < 0:
self.x_accel_vector.x=self.deceleration
elif 0 < self.velocity.x:
self.x_accel_vector.x=-self.deceleration
return self.x_accel_vector
def _get_y_accel_vector( self, controls ):
self.y_accel_vector.set_magnitude(0)
if controls.left:
if controls.up:
self.y_accel_vector.y = self.accelerate_upper_left.y
elif controls.down:
self.y_accel_vector.y = self.accelerate_lower_left.y
elif controls.right:
if controls.up:
self.y_accel_vector.y = self.accelerate_upper_right.y
elif controls.down:
self.y_accel_vector.y = self.accelerate_lower_right.y
elif controls.up:
self.y_accel_vector.y=self.accelerate_up.y
elif controls.down:
self.y_accel_vector.y=self.accelerate_down.y
elif self.velocity.y < 0:
self.y_accel_vector.y=self.deceleration
elif 0 < self.velocity.y:
self.y_accel_vector.y=-self.deceleration
return self.y_accel_vector
def _get_decel_vector( self ):
if self.velocity.is_non_zero():
self.decelerate.x=-self.velocity.x
self.decelerate.y=-self.velocity.y
self.decelerate.set_magnitude( self.deceleration )
return self.decelerate
else:
return None
def _update_state(self):
if self.position_z < 0:
if self.state != Player.JUMPING:
self.state=Player.JUMPING
self.animations[Player.JUMPING].activate()
else:
if self.state != Player.WALKING and self.velocity.is_non_zero():
self.state=Player.WALKING
self.animations[Player.WALKING].activate()
elif self.state != Player.STANDING and self.velocity.is_zero():
self.state=Player.STANDING
self.animations[Player.STANDING].activate()