def _fit_magnetic_dipole(B_orig, x0, coils, scale, method):
 from scipy.optimize import fmin_cobyla
 B = np.dot(scale, B_orig)
 B2 = np.dot(B, B)
 objective = partial(_magnetic_dipole_objective, B=B, B2=B2, coils=coils, scale=scale, method=method)
 x = fmin_cobyla(objective, x0, (), rhobeg=0.0001, rhoend=1e-05, disp=False)
 return (x, (1.0 - (objective(x) / B2)))

def _fit_magnetic_dipole ( B_orig , x0 , coils , scale , method ) : from scipy . optimize import fmin_cobyla B = np . dot ( scale , B_orig ) B2 = np . dot ( B , B ) objective = partial ( _magnetic_dipole_objective , B = B , B2 = B2 , coils = coils , scale = scale , method = method ) x = fmin_cobyla ( objective , x0 , ( ) , rhobeg = 0.0001 , rhoend = 1e-05 , disp = False ) return ( x , ( 1.0 - ( objective ( x ) / B2 ) ) )
fit a single bit of data .