-> Euler
range n
range(n)
def f(x):
return x**2
f(2)
for x in range(2)
print(x)
x = range(10
print(x)
array
et calculs¶import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6]])
a
a*1.5
col = np.array([[1], [2], [3]])
lig = np.array([[1, 2, 3]])
dimension1 = np.array([1, 2, 3])
col, lig, dimension1
col.shape, lig.shape, dimension1.shape
y1, y2 = np.array([1, 2]), np.array([1, 1])
y1+3*y2, y1+0.5*y2
range(1, 10, 2), list(range(1, 10, 2))
range(1, 10, 0.5)
# import numpy as
np.arange(1, 10, 0.5) # a, b exclu, pas
np.linspace(1, 10, 7) # a, b inclus, nb_pts
x = np.linspace(1, 10, 7)
y = np.sin(x)
y
%matplotlib inline
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 20)
y = np.sin(x)
plt.plot(x, y)
plt.plot(x, y, "+r", label="cool")
plt.legend()
plt.plot([1, 2, 3], [7, 7, 7, 7])
%xmode Plain
plt.plot([1, 2, 3], [7, 7, 7, 7])
list
et tuple
vs array
¶a_list, b_list = [1, 2], [3, 4]
a_tuple, b_tuple = (1, 2), (3, 4)
a_array, b_array = np.array([1, 2]), np.array((3, 4))
a_list+b_list, a_tuple+b_tuple, a_array+b_array
2*a_list, 2*a_tuple, 2*a_array
2. * a_list
2. * a_tuple
2. * a_array
y_0 = np.array([1, 2])
res_F = np.array([1, 1])
y = y_0 + 0.5 * res_F
y
Vous avez vu à la fin de la partie sur matplotlib
à quoi sert %xmode Plain
?
Merci d'avoir lu jusque là !