import numpy as np #=================================================== def array_from_file(file_path,verbose=False, separator = None) : """Fonction qui extrait du fichier texte dont le chemin est donné par 'file_path' un tableau numpy.ndarray de valeurs numériques, et renvoie ce tableau. Le séparateur par défaut est la tabulation ou l'espace. Sinon, on peut spécifier le spécifier par l'argument 'separator' (Exemples : ";", ",", "/").""" with open(file_path,"r",encoding="utf-8") as f : lu = f.readlines() data,nb_com = [],0 for ligne in lu : try : data.append([float(m.strip()) for m \ in ligne.split(separator)]) except : nb_com += 1 if verbose : print(nb_com,"ligne(s) de commentaires") return np.array(data) #=================================================== # Zone de test des fonctions ou classes if __name__ == "__main__" : import matplotlib.pyplot as plt tab = array_from_file("data1.txt") print("Tableau lu de taille",tab.shape) plt.plot(tab[:,2],tab[:,1],"om") plt.show()