Docsity

Numpy methods with examples, Exercises of Computer Science

Partial preview of the text

Download Numpy methods with examples and more Exercises Computer Science in PDF only on Docsity!

2

3

Numpy

paiilan)

2-D

as p.asanyP 2,3,4,31)

hp.aacyan (^) eC42)leen

Ly2,34, 5] <e lass 'humpry neaMRoy'

np.anayCe,^ 3)^ L45,6)

ndim t6 cbeck the no | dimensi'ons aa st (^) ndmin to (^) de<ine

npasacyC2,3,4,51, ndmin 5)

Annay Inding

tophint

pant

43

3-D arYay

Nagalve

1be no

LC2[4, 5,3] 6)| o’’ dimesio

anA LO)

a dimensiohs (5an array

(2,3)C4,5,]

[1,s,4]

’ to^ access^ the

have

anACcIlastelement.

PRA

(2]

2

Houw may 2-D ous Lib ong

dim no. elegens

at 1be

4322

each

look no.o’ Os 2 dim’

Fut (4)ci>

3

shape >22,e

nlim’

L

C11,20)

L1S,16(i3,14]

C, 12]

C5) 6]]

(c 2), C?,4], (5,6)

C34] \u,

(ls,6],

t341]

Caeuith (^) ale valuescan (^) aray (^) using last value ol 1he

shape

|Alwagsbe

3-D

24,6,8, 1D

To the values

hdmn (^) sing, a and veyisg

P arayC^ C24E8,lo^ nclmin=^ e)

L3,4)

imens/'o

Reshape (^) fom bpto 2-D

hee

using a vecto

’eghape C4,2 22

tbe

the

d = 6

cçmension

qns

gnaally yeino ouag y acking along

X=

joins ansay^ along^ columns^ Csam^ as^ hs^ tacy

parayIC96L1,81J)

X- np con ceden ateCenl,an axis=o)

L3, 4],

Ls,6),

hp aYray^ C^ Ci,2,33^ c4,5,^ J]) bp (^) concatenate CCat (^) ae), (^) axis=)

etackCCass (3,4]

preyCe23,C3,4) 2

sie ol^ all^ inpt^ arays^ should^ be shape np. slack’ uil increase The iensis

the unò ensionstack abog^ begbl nparrag Qc2, c aT2- np araydsackCoasl, C(C 5,63, CJ, aY a11) 22) pruot(np

same.

None, ar ays ane

9ncoeasy

{latteos d bfane

Meun bp-muan

mean

a [I4,(15,6, I11, 12, 21, 23,8, 44],193,

03, 2, 54 ), 4]]

phunlCap-meanCas)

|

np mean priolCnp:me an^ Cane,^ axy^ o)) t 23

wl| laten^ the^ caray^ ecod^ The

2 mean & [in: |44 |7+12+23 t 44 13t6t 21t3+ 9 234 2t 54+ (t

12

(

axy o’column

54 moah

prinT Cnp^ mLan^ Cas,^ axU^ =1))

31- 8-

23

15-

24.0 D |5 00

\6.

1h2 lan

22- 22-

Man

a9M= np-a((5P5cuy^ CC5,^ 3,5)

54 3]]

pintCnp mazCa)

painl Cop.maxCar,(5,4,^ 5]axy^ =o))

pxin1Lop-marl as, xu-)

(Bame {or np meay

to

3 5]

4heue

Dp. obee

min mill

an it

wel]

the

NaN

flatten

ancl then od Vlue lo 1he arny, Dpnan mean, np hanmAr, hp:napmin