#NEWLINE# def TaylorFit( block ) : #NEWLINE# #INDENT# '\n    a*s*s + b*x*x + c*y*y + d*x*y + e*s + f*x + g*y + h\n    ' #NEWLINE# A = [ ] #NEWLINE# b = [ ] #NEWLINE# for s in range ( 3 ) : #NEWLINE# #INDENT# for x in range ( 3 ) : #NEWLINE# #INDENT# for y in range ( 3 ) : #NEWLINE# #INDENT# z = block [ ( s , x , y ) ] #NEWLINE# row = [ ( s * s ) , ( x * x ) , ( y * y ) , ( x * y ) , s , x , y , 1 ] #NEWLINE# A . append ( row ) #NEWLINE# b . append ( [ z ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# ( params , _ , _ , s ) = lstsq ( A , b ) #NEWLINE# return params . flatten ( )