本文整理汇总了Python中line.Line.first_nonzero_index方法的典型用法代码示例。如果您正苦于以下问题:Python Line.first_nonzero_index方法的具体用法?Python Line.first_nonzero_index怎么用?Python Line.first_nonzero_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类line.Line
的用法示例。
在下文中一共展示了Line.first_nonzero_index方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_basepoint
# 需要导入模块: from line import Line [as 别名]
# 或者: from line.Line import first_nonzero_index [as 别名]
def set_basepoint(self):
try:
n = self.normal_vector
c = self.constant_term
basepoint_coords = ['0']*self.dimension
initial_index = Line.first_nonzero_index(n)
initial_coefficient = n.coordinates[initial_index]
basepoint_coords[initial_index] = c/initial_coefficient
self.basepoint = Vector(basepoint_coords)
except Exception as e:
if str(e) == message.NO_NONZERO_ELEMENTS_FOUND:
self.basepoint = None
else:
raise e
示例2: __str__
# 需要导入模块: from line import Line [as 别名]
# 或者: from line.Line import first_nonzero_index [as 别名]
def __str__(self):
num_decimal_places = 3
def write_coefficient(coefficient, is_initial_term=False):
coefficient = round(coefficient, num_decimal_places)
if coefficient % 1 == 0:
coefficient = int(coefficient)
output = ''
if coefficient < 0:
output += '-'
if coefficient > 0 and not is_initial_term:
output += '+'
if not is_initial_term:
output += ' '
if abs(coefficient) != 1:
output += '{}'.format(abs(coefficient))
return output
n = self.normal_vector
try:
initial_index = Line.first_nonzero_index(n)
terms = [write_coefficient(n[i], is_initial_term=(i==initial_index)) + 'x_{}'.format(i+1)
for i in range(self.dimension) if round(n[i], num_decimal_places) != 0]
output = ' '.join(terms)
except Exception as e:
if str(e) == message.NO_NONZERO_ELEMENTS_FOUND:
output = '0'
else:
raise e
constant = round(self.constant_term, num_decimal_places)
if constant % 1 == 0:
constant = int(constant)
output += ' = {}'.format(constant)
return output