本文整理汇总了Python中sympy.Matrix.solve_least_squares方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.solve_least_squares方法的具体用法?Python Matrix.solve_least_squares怎么用?Python Matrix.solve_least_squares使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Matrix
的用法示例。
在下文中一共展示了Matrix.solve_least_squares方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_conversion_matrix_for_expr
# 需要导入模块: from sympy import Matrix [as 别名]
# 或者: from sympy.Matrix import solve_least_squares [as 别名]
def _get_conversion_matrix_for_expr(expr, target_units):
from sympy import Matrix
expr_dim = Dimension(Quantity.get_dimensional_expr(expr))
dim_dependencies = expr_dim.get_dimensional_dependencies(mark_dimensionless=True)
target_dims = [Dimension(Quantity.get_dimensional_expr(x)) for x in target_units]
canon_dim_units = {i for x in target_dims for i in x.get_dimensional_dependencies(mark_dimensionless=True)}
canon_expr_units = {i for i in dim_dependencies}
if not canon_expr_units.issubset(canon_dim_units):
return None
canon_dim_units = sorted(canon_dim_units)
camat = Matrix([[i.get_dimensional_dependencies(mark_dimensionless=True).get(j, 0) for i in target_dims] for j in canon_dim_units])
exprmat = Matrix([dim_dependencies.get(k, 0) for k in canon_dim_units])
res_exponents = camat.solve_least_squares(exprmat, method=None)
return res_exponents