Re: Projet Python : importation d'un dossier csv sous forme de matrice

Liste des GroupesRevenir à fcl python 
Sujet : Re: Projet Python : importation d'un dossier csv sous forme de matrice
De : alain (at) *nospam* universite-de-strasbourg.fr.invalid (Alain Ketterlin)
Groupes : fr.comp.lang.python
Date : 03. Feb 2022, 20:45:59
Autres entêtes
Organisation : Université de Strasbourg
Message-ID : <871r0jpz4o.fsf@universite-de-strasbourg.fr.invalid>
References : 1 2 3
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)
mand1n3 <nospam_playfairalikecestatut@outlook.com.invalid> writes:

0.00055 0.00008 0.00035 0.00038 0.00048 0.00011 0.00005 0.00009 0.00031 0..00006
0 0.00014 0.00020 0.00006 0.00009 0.00048 0.00022 0.00007 0.00018 0.00026
0.00004 0.00009 0 0.00001 0.00003 0 ; 0.00085 0.00004 0.00007 0.00004 0.00070
0.00002 0.00001 0 0.00001 0 0 0.00010 0.00008 0.00002 0.00012 0.00015 0.00001
0.00022 0.00028 0.00005 0 0.00002 0 0 0 0 ; 0.00010 0.00004 0.00006 0.00010
0.00020 0.00002 0.00001 0 0.00004 0.00002 0 0.00018 0.00010 0.00002 0.00008
0.00011 0.00004 0.00003 0.00005 0.00003 0.00004 0.00020 0 0 0 0

C'est du csv inhabituel, et pour stocker une matrice 26x26 (et pas
25x25), ça s'apparente à de l'autoflagellation. Essaie :

with open (.....) as f:
    m = [[float (w) for w in b.split()] for b in f.read().split(";")]

si le fichier n'est pas trop grand, et sinon

with open (.....) as f:
    m = [[]]
    for line in f:
        for f in line.split ():
            if f == ";":
                m.append ([])
            else:
                m[-1].append (float (f))


(pas testé).

-- Alain.

Date Sujet#  Auteur
27 Jan 22 * Projet Python : importation d'un dossier csv sous forme de matrice9Mand1n3
27 Jan 22 +* Re: Projet Python : importation d'un dossier csv sous forme de matrice5yves
3 Feb 22 i`* Re: Projet Python : importation d'un dossier csv sous forme de matrice4mand1n3
3 Feb 22 i +- Re: Projet Python : importation d'un dossier csv sous forme de matrice1Alain Ketterlin
4 Feb 22 i `* Re: Projet Python : importation d'un dossier csv sous forme de matrice2yves
4 Feb 22 i  `- Re: Projet Python : importation d'un dossier csv sous forme de matrice1yves
27 Jan 22 +- Re: Projet Python : importation d'un dossier csv sous forme de matrice1Olivier Miakinen
27 Jan 22 `* Re: Projet Python : importation d'un dossier csv sous forme de matrice2K.
27 Jan 22  `- Re: Projet Python : importation d'un dossier csv sous forme de matrice1K.

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal