-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathpythonx_numpy_2.py
More file actions
86 lines (64 loc) · 1.46 KB
/
pythonx_numpy_2.py
File metadata and controls
86 lines (64 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import numpy as np
import matplotlib.pyplot as plt
# ----------------------------------------------------
# 1. Définition d'un vecteur (tableau à une dimension)
print("\n\n--- 1. Définition d'un vecteur ---\n")
# Par 'array'
X = np.array([1,2,3,4])
print(X)
# Ce n'est pas une liste python
print(type(X))
print(type([1,2,3,4]))
print(X==[1,2,3,4])
# Par 'arange'
X = np.arange(0,100,5)
print(X)
X = np.arange(1,8,0.5)
print(X)
# Par 'linspace'
X = np.linspace(0,1,num=12)
print(X)
print(len(X))
# ----------------------------------------------------
# 2. Opérations élémentaires
print("\n\n--- 2. Opérations élémentaires ---\n")
X = np.array([1,2,3,4])
print(2*X)
print(X+1)
print(X**2)
print(1/X)
print(np.sum(X))
Y = np.array([10,11,12,13])
print(X+Y)
print(X*Y)
print(np.max(X))
print(np.min(X))
print(np.sum(X))
# ----------------------------------------------------
# 3. Définition d'un vecteur (suite)
print("\n\n--- 3. Définition d'un vecteur (suite) ---\n")
# Par 'zeros'
X = np.zeros(5)
print(X)
# Par 'ones'
X = np.ones(5)
print(X)
print(7*X)
# Par 'random'
X = np.random.random(5)
print(X)
# ----------------------------------------------------
# 4. Utilisation comme une liste
print("\n\n--- 4. Utilisation comme une liste ---\n")
X = np.linspace(1,2,num=10)
print(X)
# Récupérer un élément
print(X[1])
# Parcourir tous les éléments :
for x in X:
print(x)
# Longueur
print(len(X))
print(np.shape(X))
for i in range(len(X)):
print(i,X[i])