fiche python
fiche python
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] </==/<=/!=
np.random.random(1) ->[0.60872467]
np.random.randint(1, 100)
np.random.randint(-40, 40)