Python for Science and Engg:Matrices & Least Squares FitFOSSEEDepartment of Aerospace EngineeringIIT BombaySciPy 2010, Introductory tutorialsDay 1, Session 4FOSSEE (IIT Bombay) Matrices & Curve Fitting 1 / 37Outline1 Matrices2 Least Squares Fit3 SummaryFOSSEE (IIT Bombay) Matrices & Curve Fitting 2 / 37MatricesOutline1 Matrices2 Least Squares Fit3 SummaryFOSSEE (IIT Bombay) Matrices & Curve Fitting 3 / 37MatricesMatrices: IntroductionAll matrix operations are done using arraysFOSSEE (IIT Bombay) Matrices & Curve Fitting 4 / 37MatricesMatrices: InitializingIn []: c = array([[11,12,13],[21,22,23],[31,32,33]])In []: cOut[]:array([[11, 12, 13],[21, 22, 23],[31, 32, 33]])FOSSEE (IIT Bombay) Matrices & Curve Fitting 5 / 37MatricesInitializing some special matricesIn []: ones((3,5))Out[]:array([[ 1., 1., 1., 1., 1.],[ 1., 1., 1., 1.,[ 1., 1., 1., 1., 1.]])In []: ones_like([1, 2, 3, 4])Out[]: array([1, 1, 1, 1])In []: identity(2)Out[]:array([[ 1., 0.],[ 0., 1.]])Also availablezeros, zeros_like, empty, empty_likeFOSSEE (IIT Bombay) Matrices & Curve Fitting 6 / 37MatricesAccessing elementsIn []: cOut[]:array([[11, 12, 13],[21, 22, 23],[31, 32, 33]])In []: c[1][2]Out[]: 23In []: c[1,2]Out[]: 23In []: c[1]Out[]: array([21, 22, 23])FOSSEE (IIT Bombay) Matrices & Curve Fitting 7 / 37MatricesChanging elementsIn []: c[1,1] = -22In []: cOut[]:array([[ 11, 12, 13],[ 21, -22, 23],[ 31, 32, 33]])In []: c[1] = 0In []: ...
Voir