Python for Science and Engg: Matrices & Least Squares Fit (session4)
37 Pages
English

Python for Science and Engg: Matrices & Least Squares Fit (session4)

-

Downloading requires you to have access to the YouScribe library
Learn all about the services we offer

Description

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 []: ...

Subjects

Informations

Published by
Published 27 June 2011
Reads 0
Language English
OFSSE
Python for Science and Engg: Matrices & Least Squares Fit
E(IITBom
FOSSEE
Department of Aerospace Engineering IIT Bombay
SciPy 2010, Introductory tutorials Day 1, Session 4
bay)Matrcies&uCrevFitting1/37
Outline
1
2
3
Matrices
Least Squares
Summary
FOSSEE (IIT Bombay)
Fit
Matrices
&
Curve
Fitting
2
/
37
Outline
1
2
3
Matrices
Least Squares
Summary
FOSSEE (IIT Bombay)
Fit
Matrcies
Matrices & Curve Fitting
3 / 37
Matrices:
All
matrix
Intro
operations
FOSSEE (IIT Bombay)
dMau
are
rticecstion
done
using
Matrices & Curve Fitting
arrays
4 / 37
ES(EFSO/37
13], 23], 33]])
12, 22, 32,
In []: c Out[]: array([[11, [21, [31,
In []: c = array([[11,12,13], [21,22,23], [31,32,33]])
C&seevruttiF5gniTBIIbaomMay)ictrsMceriatMnItiaiiltairec:szing
liavaoslAtiitvrFe73
ablezeros, zeros_like, empty,
gn/6
In []: ones((3,5)) Out[]: array([[ 1., 1., 1., [ 1., 1., 1., [ 1., 1., 1.,
In []: ones_like([1, 2, 3, 4]) Out[]: array([1, 1, 1, 1])
empty_like
In []: identity(2) Out[]: array([[ 1., 0.], [ 0., 1.]])
1.], 1.], 1.]])
1., 1., 1.,
SSOFI(EEoBTIaymbat)MceriCus&cialespegsomizinitlaIsinirecMtartamseci
tsenisgnlemeecAsccseMatriceriat)MeFrvCus&I(EESSOFyabmoBTI
13], 23], 33]])
In []: Out[]: In []: Out[]:
c[1][2] 23 c[1,2] 23
gn/7tiit
c[1] array([21,
22,
In []: c Out[]: array([[11, 12, [21, 22, [31, 32,
In []: Out[]:
73
23])
tsenMatriggnlemecisehCnaFO
In []: c[1,1] = -22 In []: c Out[]: array([[ 11, 12, [ 21 -22, , [ 31, 32,
How do you access onecumoln?
In []: c[1] = 0 In []: c Out[]: array([[11, 12, 13], [ 0, 0, 0], [31, 32, 33]])
13], 23], 33]])
8/37tingtiFevruC&secirta)MaymbBoIT(IEESS
moBT)yabrtaMseciFSEOSIIE(
In []: c[:,1] Out[]: array([12,
0], 33]])
In []: c[1,:] Out[]: array([0, 0, 0])
0, 32])
7
In []: c[1:3,:] Out[]: array([[ 0, 0, [31, 32,
Slicing
13], 0]])
In []: c[0:2,:] Out[]: array([[11, 12, [ 0, 0,
veFi&Curg9/3ttinaMrtseci
ecirstaMOFSSEEmbBoIT(Iriat)MayvruC&secgnittiFe7
Slicing . . .
13], 0]])
10/3
In []: c[:2,:] Out[]: array([[11, 12, [ 0, 0,
In []: c[1:,:] Out[]: array([[ 0, 0, [31, 32,
0], 33]])
In []: c[1:,:2] Out[]: array([[ 0, 0], [31, 32]])
In []: c[:,::2] Out[]: array([[11, 13], [ 0, 0], [31, 33]])
In []: c[::2,::2] Out[]: array([[11, 13], [31, 33]])
Striding
In []: c[::2,:] Out[]: array([[11, 12, [31, 32,
13], 33]])
Fevritti11gn73/aymbat)MceriCus&OFSSEEI(TIoBricesMat