TD 1 : Découverte de NumPy et Matplotlib

Programmation pour l’IA

Donnez la shape des tableaux y suivants :

  1. np.eye(5)
  2. np.stack(([1,2,3], [4,5,6]))
x1 = np.arange(5)
x2 = np.stack(x1,x1,x1)
x3 = np.stack(x2, x2, x2, x2)
x4 = np.stack(x3,x3)
y = np.sum(x3, axis=(1,2))

Donnez la valeur de y dans les programmes suivants :

x = 3*np.ones((2,2))
y = x*x
x = 2*np.ones((2,3,4))
y = np.sum(x,axis=1)
y = np.stack((np.arange(3), np.arange(5)))
x = np.stack((np.arange(3), np.arange(3)+3))
y=(x%3==1)
x = np.stack((np.arange(3), np.arange(3)+3))
z = np.stack(x, np.roll(x, 2, axis=1))
y = np.roll(z, 1, axis=0)
x=np.array([[i*j for i in range(3)] for j in range(3)])
z=np.stack( (x, np.diag((1,2,3)) ) )
y=np.sum(z, axis=(1, 2))

La matrice \(M(a_1,\dots,a_n)\) de Vandermonde est la matrice \(n \times n\) définie ainsi: la \(i\)ᵉ ligne de \(M(a_1,\dots,a_n)\) est \(a_1^i, \dots, a_n^i\). Écrire une fonction qui prend en entrée un tableau à une dimension et renvoie la matrice de Vandermonde associée.