0% found this document useful (0 votes)
10 views

Python Intro To Numpy and Matplotlib

The document discusses Python programming to define, edit, and perform arithmetic operations on NumPy arrays. It introduces NumPy and describes how to construct NumPy arrays, perform operations like mean and random number generation, and vector and matrix operations. It also discusses installing and importing Matplotlib and using basic Matplotlib functions like plt.plot() to plot points.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Python Intro To Numpy and Matplotlib

The document discusses Python programming to define, edit, and perform arithmetic operations on NumPy arrays. It introduces NumPy and describes how to construct NumPy arrays, perform operations like mean and random number generation, and vector and matrix operations. It also discusses installing and importing Matplotlib and using basic Matplotlib functions like plt.plot() to plot points.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

PAGE No

DATE

Ezperimeot No

hin
Srite Python proqram to 6tuds define , ed1t araus

and perorm avifhmetic operautions alao pefor


Selection, indeunq, merqinq, joioing,, con cafenatton

in data frames.

Introdution to Numpy
Scien tific Python code "uses a fost arra structare
calle the Dumpy aray Those h o haue
00Yed in Matl&6 wil find this very natural
Hor referente, the rumpy dacumentatto

In general qou showd manipulate numpu aroays


by isinqnumpy module functions.C7p.mean, Yor
hampl . Thia is for efficien purpases , and a
das tussion to llous below this sectton.
You Can ca culate the mean of the amay elements
either by calling the method mean2 on a nunpy
array bophluing the function 2p-mean
toith the num py drau 0S on arqument

he oau twe constructed the numpy airas abave


seems tdundant after au we olrådy oe a
qular puthonlhst ndeed, t is the "other twos
toe. have to cons truct numps arTays that mae
them super usefu
here ore many Such numpy atray tonstuetors
Herc are Some (ommonly uaed cOnstructors.
ook therm up in documehtotton.
Act N

DATE

Nampu gauns a lot of its efficienty torm beina typed.


That is, al elements in the arrdy haue the Same
lupe, Such as in teger or tloakinq point. The defaul
tpe,as Can be seen gbove, is a tloot of size
Oppropriate for the machine C6h 6itan o 64 bitnachine.

Of len you toill caant rondo m numbers ee the rondam


Constuctor.

You n qenerate random oumbers froma ormal


ditibuton toth mean O. and vartante 1

Numpy
Numpy Supports yettor operations.
Ghatcoes this mean t means that înstead of
addinq two arays, element 6y, elemeot,qou
canut sayad d the ttoo arriysNote thot
this
Dehauiour ive_difkrent from puthon ists.

On some compuker chips this ad dition actuallu boppens


in_parallel, s0 Speedups on be
hioh.
Sut euen_an yeqular chips, the aduan tage ot
qreater rtadabillty is important
JNumpuSupports a concept knoton 0s bToadeastn4
which dictates hac arrass O different sizes are
Combined mgether e are too many rules to st_
here, but Oportaotls, multiplyino an arru öy
Dumber mulkip lies 'each elemerby the number
Sddinq d number adds the number Ob eurh
elenoent
PASENo
DATE

anted the distibutton


his means thatif qou toutd do
NLS,42N S,3) you

20 arIus
Similarly, we con Creakt tuuo-dimen sidna anays.

ike lists numpu amayS ar O-indexed. 1hus te

con acceas the t t o


the n rO of, a
and m olumr
fwo- dimensional aTay ith the inditesla-1,-1

have Set length


JNumpy arrys ore isty hey
Carxaudimensidns), cun be sliced and can be
iteradOuer toith loop Below is o schemadtu
llwhraking sliung, two dimenStonal OTYOys.

Earlier when ue qeneyated tha| one dimensional


arraus o ones and Yondom numbeis , ue 9aue Ones
and rondom the number ot elements ue wanftd
in the arays In two dimensions, we need to
prouide the
thë shape ot the omay, ethe number
ot 10ws and colunns ot the axy

You con tronspose the amu

Matn' multi plitation accompanied by 7p:dot


he
Ihe operutor tuil1 do element-wise multiplicatiun

Numpy
JNumpy unttions tuilh oy default took on the
The aus O is the one qoing douwnuwards fhe qg-0xs,
So to Speak),tükereas ts 1is the one goin
ce functions
acrOSSEhe XX-ais) You ill aften use ntions
Such as mean, Sum, ith an aXIS.
See the docunne ntation to learn more about num
tuncttons as 0eeded.

Installotion of Mat plotlib


gou haue Puthon and I P alreoad installed
On a system, then installation of Matplotli6 i s

Trstal it usinq this Cammand


CsersYousnamepip i2stal matplot.b6

TE this comm.and fols then use a puthon dustnbuti-


thot alrradu has Malplotli6 instaled,ike
Anatonda, bpuder,etc

TmportMotplot.b

Once mok plot lib s installed , import it in youur


applicatons by adding he 2mpozt mddule
sfakemet.

2mportMutolo2226

uue
Now matplotlho is tm partrd and readey to
E

Chec.kinq matolot lib veLSLon


he veison gtring 1 Stared under--LTB202.

attibut.
Ry plot
Most ot the Matplotlib utilHtes lue under the puplbt
Submoduleandare usuallu imported under the
plt alas
2mportmatpotlib..puplot as plt

Noo the yplot


packaqe con be efertd to as plt

lottina a and u points


he olot C2 function 1s used to drau.oints Cnarkers
LD a duagram:
By default the plat CO function draws a line krom
point to point
The function talkes pararoe Her forspeaFying Points
in he diaqrom.
Yara roeder 1 i s on oYraq aontaining the points an
the chioartrafm
Pavcmete? 2 is an ayrou ontaning the potnts dn
the Y-aus.
tue need to plot a line from 13) tol8,10
te hoe t pass tuo 5auays C1,3JaL3, 10 to
plot functton

You might also like