import numpy as np #=================================================== def array_from_file(file_path,verbose=False) : """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 est la tabulation ou l'espace.""" 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) for m \ in ligne.split()]) 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()