# Last edited on 2021-07-31 15:29:11 by jstolfi from math import sqrt def basis_sampled_residuals_combine(R, w): # Given a list of vectors of floats, # as produced by {basis_samples_residuals_compute}, # combines them into a single vector by the Euclidean norm; # or, if {w} is not {None}, by the {w}-weighted norm. nf = len(R); assert nf > 0, "no residuals to combine" ns = len(R[0]) e = [] for ks in range(ns): sum_r2 = 0; for kf in range(nf): rfs = R[kf][ks] ws = 1 if w == None else w[ks] sum_r2 += rfs*rfs*ws es = sqrt(sum_r2) e.append(es) return e # ----------------------------------------------------------------------