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

fiche python

Uploaded by

V
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

fiche python

Uploaded by

V
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

numpy

np.float32(nb.0) / np.int8(nb) /np.float64(nb.nb) np.sqrt(m1) / np.exp(m1) / np.log10(m1)/ np.fmod(m1,m2)


np.int_([1,2,4]) -> [1 2 4] np.sum(m1) ; np.sum(m1,axis=0 (col) ou 1(ligne))
np.prod(m1, axis=0 ou 1) multiplication
np.array([1, 2, 3], dtype='f') -> [1 2 3] np.mean(m1) Moyenne / np.std(m1) ecart-type
np.zeros((2, 3)) -> [[0., 0.],\n[0., 0.]] np.std(m1)

np.ones((a, b))
np.arange(3, dtype=np.uint8) -> [0 1 2]
np.arange(2, 10, 2) -> [2, 4, 6, 8]
np.arange(3) -> [0, 1, 2]
np.arange(2, 6) -> [2, 3, 4, 5 ]
np.arange(2, 6, dtype=float) -> [2., 3., 4., 5.]
np.linspace(5, 8, 4(si rien=50)) -> [5., 6. ,7. ,8 ]
np.indices((3, 3))
->[[[0 0 0]\n[]1 1 1]\n[2 2 2] -> np.indices((3, 3))[0]
ou ->[[[0 1 2]\n[0 1 2]\n[0 1 2] -> np.indices((3, 3))[1]

mat :
.ndim gives the dimensison (2 = matrix, 1 = vector)
.size gives the total number of element
.shape donne ou cree() nb d’elts dans chaque axes
.dtype gives the data type contained the array
.reshape il faut le mm nb d’elt
.itemsize comme .shape mais int
x = np.arange(20) ; x[5:9] -> [ 5 6 7 8 ]
x = [1, 2, 3, 4, 5] ; x[::-1]-> [5, 4, 3, 2, 1]
np.array([1, 2, 3, 4, 5]) : x[:-3]->[1 2] / x[:3]->[1 2 3]
x[-3:]->[3 4 5] ; x[3:]->[4 5]
np.array([2, -4, 5, -6, 0]) ; x[x > 0]->[2, 5] </==/<=/!=

my_array[1, 2] / my_list[1][2] / my_tuple[1][2] tuple


avec () # Access element at row 1 , column 2
x=np.array([('Sita', 39, 51.8), ('Gita', 23, 47.5)],
dtype=[('name', 'U10'), ('age', 'i4'), ('weight', 'f4')])
-> [('Sita', 39, 51.8) ('Gita', 23, 47.5)]
x[1] / x['age']

np.zeros(2) ->[0., 0.]


np.zeros((2, 2), dtype = 'int') ->array([[0, 0],\n[0, 0]])

np.random.random(1) ->[0.60872467]
np.random.randint(1, 100)
np.random.randint(-40, 40)

np.full((2,2), 6) ->[[6, 6],\n[6, 6]]


np.full(2, 9) -> [2 ,2]

np.tile([0, 1], 2) -> [0, 1, 0, 1]


np.tile([0, 1], [2, 2]) -> [[0, 1, 0, 1]\n[0, 1, 0, 1]]
np.eye(2) -> [[1., 0.]\n[0., 1.]]
np.eye(3) -> -> [[1., 0., 0.]\n[0., 1., 0.]\n[0., 0., 1.]]

You might also like