import numpy as np
np.set_printoptions(precision=3, threshold=0, edgeitems=5)
import numpy_html
np.array([4, 5])
np.array([4, 10, 5])
np.array((4, 5))
np.zeros((4, 5))
np.zeros( (4, 5) )
sh = (4, 5)
np.zeros(sh)
np.ones((5, 4))
np.random.uniform(2, 3, (4, 5))
np.random.normal(2, 3, (4, 5))
tab1000 = np.random.normal(1000, 0.01, (4, 5))
tab1000
print(np.mean(tab1000))
1000.1037314934902
print(np.std(tab1000))
0.8370454052254138
np.linspace(3, 4, 5)
np.arange(100, 1000, 10)
# Q9
b = np.arange(100, 1000, 10)
print(b.shape)
print(np.shape(b))
(90,) (90,)
np.linspace(100, 200, 5)
np.arange(100, 201, 25)
l = [100, 125, 150, 175, 200]
np.array(l)
# ou directement np.array([100, 125, 150, 175, 200])
np.arange(5) * 25 + 100
print(np.shape( np.array([4,5]) ))
(2,)
# comment creer tableau avec 1 ligne, 2 colonnes
#np.zeros((1,2))
np.array( [ [4, 5] ] )
# np.zeros etc accèptent des entiers à la place de shape
np.testing.assert_allclose(
np.zeros(100),
np.zeros((100,))
)
print("OK")
OK
print(np.zeros(5))
print("----")
print(np.zeros((1,5)))
print("----")
print(np.zeros((2,5)))
[0. 0. 0. 0. 0.] ---- [[0. 0. 0. 0. 0.]] ---- [[0. 0. 0. 0. 0.] [0. 0. 0. 0. 0.]]
print(np.shape( np.zeros((4, 5)) ))
(4, 5)
print(np.shape( np.ones((5, 4)) ))
(5, 4)
print(np.shape( np.random.uniform(2, 3, (4, 5)) ))
(4, 5)
print(np.shape( np.random.normal(2, 3, (4, 5)) ))
(4, 5)
print(np.shape( np.linspace(10, 20, 30) ))
(30,)
print(np.shape( np.arange(100, 1000, 10) ))
(90,)
print(np.shape( np.ones((100, )) ))
(100,)
a = np.zeros((5,))
print(a)
print(np.shape(a))
a
[0. 0. 0. 0. 0.] (5,)
a = np.zeros((5, 1))
print(a)
print(np.shape(a))
a
[[0.] [0.] [0.] [0.] [0.]] (5, 1)
a = np.zeros((1, 5))
print(a)
print(np.shape(a))
a
[[0. 0. 0. 0. 0.]] (1, 5)
print(np.shape( np.ones((100)).reshape(( 5, 20)) ))
(5, 20)
print(np.shape( np.ones((100)).reshape(( -1, 20)) ))
(5, 20)
print(np.shape( np.ones((100)).reshape(( 5, -1)) ))
(5, 20)
print(np.shape( np.ones((100)).reshape(( -1, 5)) ))
(20, 5)
np.linspace(2, 5, 16)
np.linspace(2, 5, 16).reshape((2, 8))
np.linspace(2, 5, 16).reshape((-1, 4))