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

Numpy Notes Csai

1. NumPy is a library for working with multi-dimensional numerical arrays in Python. It supports mathematical operations on arrays and matrices. 2. NumPy arrays can have multiple dimensions. Common operations include sorting, aggregation functions, random number generation, linear algebra, and more. 3. NumPy provides functions for creating, manipulating, and joining arrays like arange, zeros, ones, vstack, hstack, and concatenate.

Uploaded by

Nishi
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)
497 views

Numpy Notes Csai

1. NumPy is a library for working with multi-dimensional numerical arrays in Python. It supports mathematical operations on arrays and matrices. 2. NumPy arrays can have multiple dimensions. Common operations include sorting, aggregation functions, random number generation, linear algebra, and more. 3. NumPy provides functions for creating, manipulating, and joining arrays like arange, zeros, ones, vstack, hstack, and concatenate.

Uploaded by

Nishi
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/ 8

NUMPy numerita plethon

We ude it to (neahe n-dimensiOnal ana

Avruy
1-, Nesked ists a Omyn-dimumduéns a

S4 -D
Supports ana matnuuatia
Doesn+ Suppot mathuafia)
uuhioms
4untions
ist lt 3.910|e9. np arroul[, 1)
+
np.anay(T3,97)
t i t (,)+
[1, 2,3,9] Oay (L 4, u)
PRIORITY LIST
inme aud
3 Tajeey mone String Pront
6 pale .Ploot
int
import numpy a P
neotinq amay Bocfeunalo
xnp-amay [i, 4,F1) mvnty

Pint(x) [i,4,T1
Xshape (3,)opie
PF 1 1 0) ~Drimeuuions
X. ndim
RetunUeu{henen
Ommu
ARANGt 2

np- arange (1, 10 tuw


munnbes.
Omy

Print y)
L,1,5.1, 5,6,7,8,9)
X:np drange(1,
10, 2)
print ( ) - [,3,,7,9]
Stopping Poin, Attstep, & num)
no Numbers
Linspace (Sorting foint,
ne ced an Opthonal
nee isany t e n A Oant

5)
0 np. inspate (t, 10, retstp- Tue, num

bek n42.3-
ormay l[1. AnD-2no.3) m.4 1o.)J). dibo
Wanf amy (L1,2,4.5])
Teros b Ones w

llo., 0,0.,0., 0.3) OrrayLI,2., 4.5))


np. zeros(5)- aruy
([i., t., , I.,1.1)
npamy (1,11,[3,43,[S,¢17)
npon es(5) away
2
np onesl [4,91). Orray([. , 13, z

[1.11, L[,2,
.,1.1, [3,41,
T.,1.1) [s,63
o n P : zeros-ike W)
RAND OM ariy [o.,0., 0.J)
(313))
random Size
=

random.
n array ( [ L K a n gw
p.random randint ( 5, 50, 6
hhis i l l hu 6 rondom inHa
- betwen 5 to 9.
-11)
arrauy (L 5,1, 38,u1, 23, 431)

Similar to randint,
np
random randint (5.50, [1,37)
randn will fie
array L[ s 16, 20o3,
T4,19, 3811)

ou (an change amy array Uou taM dovt M ayra Wain


yaluu ud in9 neluyinq ,sortl)

w np:avray(LI, 2,4]) p-Array([ 6,4,2,-13)


w[21-6 w.SortO
Pont (w)
n t luw)
[-1, 2,, 61
[ ,2,1
y np.array([[1, 2, 3, 4, 5]. [6, 7, 8, 9, 10], [11, 11, 11, 11, 11]]
yte]
array([1, 2, 3, 4, ])

yte:2]

array( 61,, 7,
2, 8,
3, 9, 10]1
1e]])

y,e:2] # all three rows, first and second element

array([[ 1, 2].
6 , 7]
[11, 11]])

all columns of those rows


: y[e:2, :] # tiwo rows,

array(1
[6,
47, 8, 9,
9,
51.
1011)
10]1)
y fe, 2]1
->alL rows

# [e, 2] --> oth and 2nd element

array(I 1, 3
6, 8]1
[11, 11]])

:#For continuous elements use coLon

# for spec ific positions encLose the positions in a list

a y[:, 0:3]
print(a)
print()
b y[: [e, 3]]
print (b)
1 2 3
6 7 8]
[11 11 11]]

I[ 1 4]
6 9]
[11 11]]
SEED
rondom.3ted ( 2) Runit Seuwa/ +tim, Qutfrut wil te
1P.
np rondom.randint i,10o)

Randint qentates random integev


Serd aspigns the ol (x nD. Writen m Se cd bratkek,j.e, 2)
T t cals the number: hat id ony, Hhatw, id 2. numbe
max.
Number in e d bralket Cm a m y i n g nduy mn

o
w econ the id. Tndex
mumeer
INDEX 0 1

X= np. orray ([5, 50, 89, 100, 2, 31)


np maxtx) 9p min (x) 0rgmax ( X) p. arg in(K)
2

the eltments in intneasing order Tpaus


e Pr9 sorf > Arrangeu
hem witn hir initia indLy Yaluu

n-dimimAiona urray
np.argdorttx)
array ([, 5,0,,2,31 Let on avray y, dutu that
Re shape y.shape, (4,6)
no ()
9. reshape (no 0 , no. r
roud
Coum

Surh thut xc 4 X6

Oray. 6 shape (I,24)


'Flaten ve jiues a e 1-0

row mumbers
Bhoubod * Some wnneth mn wue
dor hstalk a

vSHak> olumn number &hould kanne .


tor
wnta keni aXis =0
Vs Fotk
=

hstatk
oneatenatr, axís 1
y

array([[ 1, 2, 3, 4, 5, 6]
[4, 6, 7, 8 , 9, 10],
[11, 11, 11, 11, 11, 11].
1, 1, 1, 1, 1, 1]])

array([[ 1, 2,

[10, 10, 10, 10, 10, 10].


[ 2, 2, 2, 2, 2, 2]1)
np.vstack((y, z))
array([1, 2, 3, 5, 6].
4, 6, 7, 8, 9, 10].
[11, 11, 11, 11, 11, 11].
[1, 1, 1, 1, 1, 1].
1, 2, 3, 4 5, 6,
4, 6, 7 8, 9, 10].
[10, 10, 10, 10, 1e, 18].
[ 2, 2, 2, 2, 2, 2]])
np.concatenate ( [y. z], axis e )

array([[ 1, 3,
2, 5, 6].
[ 4, 6, 7, 8, 9, 10].
[11, 11, 11, 11, 11, 11]1
[1, 1, 1, 1, 1, 1.
[1, 2, 3, 4 5, 6],
[ 4, 6, 7, 8, 9, 10),
[10, 10, 10, 10, 1e, 18],
2 , 2, 2, 2, 2, 2]1)
np.hstack ((y, z))
array ([[ 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6].
[ 4, 6, 7, 9, 10, 4, 5,
8, 7. 8, 9, 10],
[11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10]
[ 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]1)

np.concatenate([y, z], axis -


1)
array([[ 1, 2, 3, 4, 6, 1, 2, 3, 4, 5, 6],
4, 7, 8, 9, 18, 4, 6, 7, 8, 9, 10],
6,
[11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10],
i 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 211)

You might also like