Script started on Wed 12 Mar 2014 06:31:24 PM CET zhentao@martagon:~/ipython/ipython-1.2.1$ ./ipython Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) Type "copyright", "credits" or "license" for more information. IPython 1.2.1 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: open("ages-2013.csv") Out[1]: In [2]: contenu = open("ages-2013.csv").read() In [3]: contenu Out[3]: ",Homme 0 \xc3\xa0 19 ans,Homme 20 \xc3\xa0 39 ans,Homme 40 \xc3\xa0 59 ans,Homme 60 \xc3\xa0 74 ans,Homme 75 ans et plus,Femme 0 \xc3\xa0 19 ans,Femme 20 \xc3\xa0 39 ans,Femme 40 \xc3\xa0 59 ans,Femme 60 \xc3\xa0 74 ans,Femme 75 ans et plus\nAlsace,228114,232452,262694,130053,56677,217353,236656,264906,136065,96050\nAquitaine,379188,375522,442336,258219,134564,362797,380724,463419,287831,218792\nAuvergne,149863,151217,186737,112709,56890,144904,147238,187984,121273,96815\nBasse-Normandie,180286,163913,198799,114750,59364,171245,162845,201032,126902,100106\nBourgogne,190917,180448,220932,135654,68838,180239,179091,225662,146790,115360\nBretagne,404425,377284,438332,243655,120932,384595,364403,439660,275062,211311\nCentre,316000,287444,343730,197806,104200,301664,289689,352005,215998,164395\nChampagne-Ardenne,165662,161234,178757,98686,45586,156874,156639,183057,108001,79001\nCorse,34449,38174,44863,27413,13281,31981,37955,45639,28808,19557\nFranche-Comt\xc3\xa9,148568,142446,158047,88252,41835,140297,137631,158994,93502,68334\nHaute-Normandie,240430,223697,244544,126904,58094,228903,225644,254216,143837,101833\n\xc3\x8ele-de-France,1577836,1691173,1541462,681540,294404,1520883,1776935,1622740,766243,505147\nLanguedoc-Roussillon,323531,303846,352466,218703,111078,310103,314168,377551,242656,173184\nLimousin,78873,78070,99565,64047,36660,74703,77118,102356,69586,60069\nLorraine,282098,295231,323772,167594,78413,267699,285267,331210,185115,134258\nMidi-Pyr\xc3\xa9n\xc3\xa9es,345982,352155,394843,221874,122624,326325,344634,405369,242878,189823\nNord - Pas-de-Calais,555889,524570,521322,249759,105909,527692,528497,539401,292617,206500\nPays de la Loire,476524,436245,479881,256902,132699,455910,430373,486553,286486,216778\nPicardie,255736,235543,260282,132319,57004,243456,235678,264276,143076,97367\nPoitou-Charentes,205357,193377,239316,148974,81273,194893,192074,248468,162519,125908\nProvence-Alpes-C\xc3\xb4te d'Azur,579662,562326,638386,384072,199682,552899,574326,690316,436128,319648\nRh\xc3\xb4ne-Alpes,829188,805096,838716,435937,207144,789832,810200,859535,478407,339415\n" In [4]: contenu.split("\n") Out[4]: [',Homme 0 \xc3\xa0 19 ans,Homme 20 \xc3\xa0 39 ans,Homme 40 \xc3\xa0 59 ans,Homme 60 \xc3\xa0 74 ans,Homme 75 ans et plus,Femme 0 \xc3\xa0 19 ans,Femme 20 \xc3\xa0 39 ans,Femme 40 \xc3\xa0 59 ans,Femme 60 \xc3\xa0 74 ans,Femme 75 ans et plus', 'Alsace,228114,232452,262694,130053,56677,217353,236656,264906,136065,96050', 'Aquitaine,379188,375522,442336,258219,134564,362797,380724,463419,287831,218792', 'Auvergne,149863,151217,186737,112709,56890,144904,147238,187984,121273,96815', 'Basse-Normandie,180286,163913,198799,114750,59364,171245,162845,201032,126902,100106', 'Bourgogne,190917,180448,220932,135654,68838,180239,179091,225662,146790,115360', 'Bretagne,404425,377284,438332,243655,120932,384595,364403,439660,275062,211311', 'Centre,316000,287444,343730,197806,104200,301664,289689,352005,215998,164395', 'Champagne-Ardenne,165662,161234,178757,98686,45586,156874,156639,183057,108001,79001', 'Corse,34449,38174,44863,27413,13281,31981,37955,45639,28808,19557', 'Franche-Comt\xc3\xa9,148568,142446,158047,88252,41835,140297,137631,158994,93502,68334', 'Haute-Normandie,240430,223697,244544,126904,58094,228903,225644,254216,143837,101833', '\xc3\x8ele-de-France,1577836,1691173,1541462,681540,294404,1520883,1776935,1622740,766243,505147', 'Languedoc-Roussillon,323531,303846,352466,218703,111078,310103,314168,377551,242656,173184', 'Limousin,78873,78070,99565,64047,36660,74703,77118,102356,69586,60069', 'Lorraine,282098,295231,323772,167594,78413,267699,285267,331210,185115,134258', 'Midi-Pyr\xc3\xa9n\xc3\xa9es,345982,352155,394843,221874,122624,326325,344634,405369,242878,189823', 'Nord - Pas-de-Calais,555889,524570,521322,249759,105909,527692,528497,539401,292617,206500', 'Pays de la Loire,476524,436245,479881,256902,132699,455910,430373,486553,286486,216778', 'Picardie,255736,235543,260282,132319,57004,243456,235678,264276,143076,97367', 'Poitou-Charentes,205357,193377,239316,148974,81273,194893,192074,248468,162519,125908', "Provence-Alpes-C\xc3\xb4te d'Azur,579662,562326,638386,384072,199682,552899,574326,690316,436128,319648", 'Rh\xc3\xb4ne-Alpes,829188,805096,838716,435937,207144,789832,810200,859535,478407,339415', ''] In [5]: contenu.split("\n")[0] Out[5]: ',Homme 0 \xc3\xa0 19 ans,Homme 20 \xc3\xa0 39 ans,Homme 40 \xc3\xa0 59 ans,Homme 60 \xc3\xa0 74 ans,Homme 75 ans et plus,Femme 0 \xc3\xa0 19 ans,Femme 20 \xc3\xa0 39 ans,Femme 40 \xc3\xa0 59 ans,Femme 60 \xc3\xa0 74 ans,Femme 75 ans et plus' In [6]: contenu.split("\n")[1] Out[6]: 'Alsace,228114,232452,262694,130053,56677,217353,236656,264906,136065,96050' In [7]: lignes = contenu.split("\n") In [8]: ligne1 = lignes[1] In [9]: ligne1 Out[9]: 'Alsace,228114,232452,262694,130053,56677,217353,236656,264906,136065,96050' In [10]: ligne1 KeyboardInterrupt In [10]: ligne1.split(",") Out[10]: ['Alsace', '228114', '232452', '262694', '130053', '56677', '217353', '236656', '264906', '136065', '96050'] In [11]: ligne1.split(",")[-1] Out[11]: '96050' In [12]: entree = ligne1.split(",")[-1] In [13]: entree Out[13]: '96050' In [14]: entree+1 --------------------------------------------------------------------------- TypeError Traceback (most recent call last) in () ----> 1 entree+1 TypeError: cannot concatenate 'str' and 'int' objects In [15]: int(entree) Out[15]: 96050 In [16]: int(entree) + 1 Out[16]: 96051 In [17]: ligne1.split(",")[-1] KeyboardInterrupt In [17]: rangee = [] In [18]: for entree in ligne1.split(",")[1:]: ....: pop = int(entree) ....: rangee.append(pop) ....: In [19]: rangee Out[19]: [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050] In [20]: rangees = [] In [21]: for rangee in lignes[1:]: ....: rangee = [] ....: for entree in ligne1.split(",")[1:]: ....: pop = int(entree) ....: rangee.append(pop) ....: rangees.append(rangee) ....: In [22]: rangees Out[22]: [[228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050]] In [23]: print rangees [[228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050]] In [24]: import scipy as sp In [25]: sp.arr sp.array sp.array_equiv sp.array_str sp.array2string sp.array_repr sp.array_equal sp.array_split In [25]: sp.array(rangees) Out[25]: array([[228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050]]) In [26]: population = sp.array(rangees) In [27]: lignes[0] Out[27]: ',Homme 0 \xc3\xa0 19 ans,Homme 20 \xc3\xa0 39 ans,Homme 40 \xc3\xa0 59 ans,Homme 60 \xc3\xa0 74 ans,Homme 75 ans et plus,Femme 0 \xc3\xa0 19 ans,Femme 20 \xc3\xa0 39 ans,Femme 40 \xc3\xa0 59 ans,Femme 60 \xc3\xa0 74 ans,Femme 75 ans et plus' In [28]: lignes[0].split(",") Out[28]: ['', 'Homme 0 \xc3\xa0 19 ans', 'Homme 20 \xc3\xa0 39 ans', 'Homme 40 \xc3\xa0 59 ans', 'Homme 60 \xc3\xa0 74 ans', 'Homme 75 ans et plus', 'Femme 0 \xc3\xa0 19 ans', 'Femme 20 \xc3\xa0 39 ans', 'Femme 40 \xc3\xa0 59 ans', 'Femme 60 \xc3\xa0 74 ans', 'Femme 75 ans et plus'] In [29]: population[:,:5] Out[29]: array([[228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677], [228114, 232452, 262694, 130053, 56677]]) In [30]: population Out[30]: array([[228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050]]) In [31]: for ligne in lignes[1:]: rangee = [] for entree in ligne.split(",")[1:]: pop = int(entree) rangee.append(pop) rangees.append(rangee) ....: In [32]: population = sp.array(rangees) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) in () ----> 1 population = sp.array(rangees) ValueError: setting an array element with a sequence. In [33]: rangees = [] In [34]: for ligne in lignes[1:]: rangee = [] for entree in ligne.split(",")[1:]: pop = int(entree) rangee.append(pop) rangees.append(rangee) ....: In [35]: rangees Out[35]: [[228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [379188, 375522, 442336, 258219, 134564, 362797, 380724, 463419, 287831, 218792], [149863, 151217, 186737, 112709, 56890, 144904, 147238, 187984, 121273, 96815], [180286, 163913, 198799, 114750, 59364, 171245, 162845, 201032, 126902, 100106], [190917, 180448, 220932, 135654, 68838, 180239, 179091, 225662, 146790, 115360], [404425, 377284, 438332, 243655, 120932, 384595, 364403, 439660, 275062, 211311], [316000, 287444, 343730, 197806, 104200, 301664, 289689, 352005, 215998, 164395], [165662, 161234, 178757, 98686, 45586, 156874, 156639, 183057, 108001, 79001], [34449, 38174, 44863, 27413, 13281, 31981, 37955, 45639, 28808, 19557], [148568, 142446, 158047, 88252, 41835, 140297, 137631, 158994, 93502, 68334], [240430, 223697, 244544, 126904, 58094, 228903, 225644, 254216, 143837, 101833], [1577836, 1691173, 1541462, 681540, 294404, 1520883, 1776935, 1622740, 766243, 505147], [323531, 303846, 352466, 218703, 111078, 310103, 314168, 377551, 242656, 173184], [78873, 78070, 99565, 64047, 36660, 74703, 77118, 102356, 69586, 60069], [282098, 295231, 323772, 167594, 78413, 267699, 285267, 331210, 185115, 134258], [345982, 352155, 394843, 221874, 122624, 326325, 344634, 405369, 242878, 189823], [555889, 524570, 521322, 249759, 105909, 527692, 528497, 539401, 292617, 206500], [476524, 436245, 479881, 256902, 132699, 455910, 430373, 486553, 286486, 216778], [255736, 235543, 260282, 132319, 57004, 243456, 235678, 264276, 143076, 97367], [205357, 193377, 239316, 148974, 81273, 194893, 192074, 248468, 162519, 125908], [579662, 562326, 638386, 384072, 199682, 552899, 574326, 690316, 436128, 319648], [829188, 805096, 838716, 435937, 207144, 789832, 810200, 859535, 478407, 339415], []] In [36]: lignes[-1] Out[36]: '' In [37]: for ligne in lignes[1:]: rangee = [] for entree in ligne.split(",")[1:]: pop = int(entree) rangee.append(pop) rangees.append(rangee) KeyboardInterrupt In [37]: rangees = [] In [38]: for ligne in lignes[1:-1]: rangee = [] for entree in ligne.split(",")[1:]: pop = int(entree) rangee.append(pop) rangees.append(rangee) ....: In [39]: rangees Out[39]: [[228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [379188, 375522, 442336, 258219, 134564, 362797, 380724, 463419, 287831, 218792], [149863, 151217, 186737, 112709, 56890, 144904, 147238, 187984, 121273, 96815], [180286, 163913, 198799, 114750, 59364, 171245, 162845, 201032, 126902, 100106], [190917, 180448, 220932, 135654, 68838, 180239, 179091, 225662, 146790, 115360], [404425, 377284, 438332, 243655, 120932, 384595, 364403, 439660, 275062, 211311], [316000, 287444, 343730, 197806, 104200, 301664, 289689, 352005, 215998, 164395], [165662, 161234, 178757, 98686, 45586, 156874, 156639, 183057, 108001, 79001], [34449, 38174, 44863, 27413, 13281, 31981, 37955, 45639, 28808, 19557], [148568, 142446, 158047, 88252, 41835, 140297, 137631, 158994, 93502, 68334], [240430, 223697, 244544, 126904, 58094, 228903, 225644, 254216, 143837, 101833], [1577836, 1691173, 1541462, 681540, 294404, 1520883, 1776935, 1622740, 766243, 505147], [323531, 303846, 352466, 218703, 111078, 310103, 314168, 377551, 242656, 173184], [78873, 78070, 99565, 64047, 36660, 74703, 77118, 102356, 69586, 60069], [282098, 295231, 323772, 167594, 78413, 267699, 285267, 331210, 185115, 134258], [345982, 352155, 394843, 221874, 122624, 326325, 344634, 405369, 242878, 189823], [555889, 524570, 521322, 249759, 105909, 527692, 528497, 539401, 292617, 206500], [476524, 436245, 479881, 256902, 132699, 455910, 430373, 486553, 286486, 216778], [255736, 235543, 260282, 132319, 57004, 243456, 235678, 264276, 143076, 97367], [205357, 193377, 239316, 148974, 81273, 194893, 192074, 248468, 162519, 125908], [579662, 562326, 638386, 384072, 199682, 552899, 574326, 690316, 436128, 319648], [829188, 805096, 838716, 435937, 207144, 789832, 810200, 859535, 478407, 339415]] In [40]: population = sp.array(rangees) In [41]: population Out[41]: array([[ 228114, 232452, 262694, 130053, 56677, 217353, 236656, 264906, 136065, 96050], [ 379188, 375522, 442336, 258219, 134564, 362797, 380724, 463419, 287831, 218792], [ 149863, 151217, 186737, 112709, 56890, 144904, 147238, 187984, 121273, 96815], [ 180286, 163913, 198799, 114750, 59364, 171245, 162845, 201032, 126902, 100106], [ 190917, 180448, 220932, 135654, 68838, 180239, 179091, 225662, 146790, 115360], [ 404425, 377284, 438332, 243655, 120932, 384595, 364403, 439660, 275062, 211311], [ 316000, 287444, 343730, 197806, 104200, 301664, 289689, 352005, 215998, 164395], [ 165662, 161234, 178757, 98686, 45586, 156874, 156639, 183057, 108001, 79001], [ 34449, 38174, 44863, 27413, 13281, 31981, 37955, 45639, 28808, 19557], [ 148568, 142446, 158047, 88252, 41835, 140297, 137631, 158994, 93502, 68334], [ 240430, 223697, 244544, 126904, 58094, 228903, 225644, 254216, 143837, 101833], [1577836, 1691173, 1541462, 681540, 294404, 1520883, 1776935, 1622740, 766243, 505147], [ 323531, 303846, 352466, 218703, 111078, 310103, 314168, 377551, 242656, 173184], [ 78873, 78070, 99565, 64047, 36660, 74703, 77118, 102356, 69586, 60069], [ 282098, 295231, 323772, 167594, 78413, 267699, 285267, 331210, 185115, 134258], [ 345982, 352155, 394843, 221874, 122624, 326325, 344634, 405369, 242878, 189823], [ 555889, 524570, 521322, 249759, 105909, 527692, 528497, 539401, 292617, 206500], [ 476524, 436245, 479881, 256902, 132699, 455910, 430373, 486553, 286486, 216778], [ 255736, 235543, 260282, 132319, 57004, 243456, 235678, 264276, 143076, 97367], [ 205357, 193377, 239316, 148974, 81273, 194893, 192074, 248468, 162519, 125908], [ 579662, 562326, 638386, 384072, 199682, 552899, 574326, 690316, 436128, 319648], [ 829188, 805096, 838716, 435937, 207144, 789832, 810200, 859535, 478407, 339415]]) In [42]: population[:,:5] Out[42]: array([[ 228114, 232452, 262694, 130053, 56677], [ 379188, 375522, 442336, 258219, 134564], [ 149863, 151217, 186737, 112709, 56890], [ 180286, 163913, 198799, 114750, 59364], [ 190917, 180448, 220932, 135654, 68838], [ 404425, 377284, 438332, 243655, 120932], [ 316000, 287444, 343730, 197806, 104200], [ 165662, 161234, 178757, 98686, 45586], [ 34449, 38174, 44863, 27413, 13281], [ 148568, 142446, 158047, 88252, 41835], [ 240430, 223697, 244544, 126904, 58094], [1577836, 1691173, 1541462, 681540, 294404], [ 323531, 303846, 352466, 218703, 111078], [ 78873, 78070, 99565, 64047, 36660], [ 282098, 295231, 323772, 167594, 78413], [ 345982, 352155, 394843, 221874, 122624], [ 555889, 524570, 521322, 249759, 105909], [ 476524, 436245, 479881, 256902, 132699], [ 255736, 235543, 260282, 132319, 57004], [ 205357, 193377, 239316, 148974, 81273], [ 579662, 562326, 638386, 384072, 199682], [ 829188, 805096, 838716, 435937, 207144]]) In [43]: hommes = population[:,:5] In [44]: femmes = population[:,5:] In [45]: femmes Out[45]: array([[ 217353, 236656, 264906, 136065, 96050], [ 362797, 380724, 463419, 287831, 218792], [ 144904, 147238, 187984, 121273, 96815], [ 171245, 162845, 201032, 126902, 100106], [ 180239, 179091, 225662, 146790, 115360], [ 384595, 364403, 439660, 275062, 211311], [ 301664, 289689, 352005, 215998, 164395], [ 156874, 156639, 183057, 108001, 79001], [ 31981, 37955, 45639, 28808, 19557], [ 140297, 137631, 158994, 93502, 68334], [ 228903, 225644, 254216, 143837, 101833], [1520883, 1776935, 1622740, 766243, 505147], [ 310103, 314168, 377551, 242656, 173184], [ 74703, 77118, 102356, 69586, 60069], [ 267699, 285267, 331210, 185115, 134258], [ 326325, 344634, 405369, 242878, 189823], [ 527692, 528497, 539401, 292617, 206500], [ 455910, 430373, 486553, 286486, 216778], [ 243456, 235678, 264276, 143076, 97367], [ 194893, 192074, 248468, 162519, 125908], [ 552899, 574326, 690316, 436128, 319648], [ 789832, 810200, 859535, 478407, 339415]]) In [46]: rangees_hommes = [] In [47]: rangees_femmes = [] In [48]: for ligne in lignes[1:-1]: rangee = [] for entree in ligne.split(",")[1:]: pop = int(entree) rangee.append(pop) hommes.append(rangee[:5]) ....: femmes.append(rangee[5:]) ....: --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) in () 4 pop = int(entree) 5 rangee.append(pop) ----> 6 hommes.append(rangee[:5]) 7 femmes.append(rangee[5:]) 8 AttributeError: 'numpy.ndarray' object has no attribute 'append' In [49]: for ligne in lignes[1:-1]: rangee = [] for entree in ligne.split(",")[1:]: pop = int(entree) rangee.append(pop) rangees_hommes.append(rangee[:5]) rangees_femmes.append(rangee[5:]) ....: In [50]: rangees_hommes Out[50]: [[228114, 232452, 262694, 130053, 56677], [379188, 375522, 442336, 258219, 134564], [149863, 151217, 186737, 112709, 56890], [180286, 163913, 198799, 114750, 59364], [190917, 180448, 220932, 135654, 68838], [404425, 377284, 438332, 243655, 120932], [316000, 287444, 343730, 197806, 104200], [165662, 161234, 178757, 98686, 45586], [34449, 38174, 44863, 27413, 13281], [148568, 142446, 158047, 88252, 41835], [240430, 223697, 244544, 126904, 58094], [1577836, 1691173, 1541462, 681540, 294404], [323531, 303846, 352466, 218703, 111078], [78873, 78070, 99565, 64047, 36660], [282098, 295231, 323772, 167594, 78413], [345982, 352155, 394843, 221874, 122624], [555889, 524570, 521322, 249759, 105909], [476524, 436245, 479881, 256902, 132699], [255736, 235543, 260282, 132319, 57004], [205357, 193377, 239316, 148974, 81273], [579662, 562326, 638386, 384072, 199682], [829188, 805096, 838716, 435937, 207144]] In [51]: for ligne in lignes[1:-1]: rangee = [] for entree in ligne.split(",")[1:]: pop = int(entree) rangee.append(pop) rangees_hommes.append(rangee[:5]) rangees_femmes.append(rangee[5:]) KeyboardInterrupt In [51]: hommes.shape() --------------------------------------------------------------------------- TypeError Traceback (most recent call last) in () ----> 1 hommes.shape() TypeError: 'tuple' object is not callable In [52]: size(hommes) --------------------------------------------------------------------------- NameError Traceback (most recent call last) in () ----> 1 size(hommes) NameError: name 'size' is not defined In [53]: sp.size(hommes) Out[53]: 110 In [54]: hommes Out[54]: array([[ 228114, 232452, 262694, 130053, 56677], [ 379188, 375522, 442336, 258219, 134564], [ 149863, 151217, 186737, 112709, 56890], [ 180286, 163913, 198799, 114750, 59364], [ 190917, 180448, 220932, 135654, 68838], [ 404425, 377284, 438332, 243655, 120932], [ 316000, 287444, 343730, 197806, 104200], [ 165662, 161234, 178757, 98686, 45586], [ 34449, 38174, 44863, 27413, 13281], [ 148568, 142446, 158047, 88252, 41835], [ 240430, 223697, 244544, 126904, 58094], [1577836, 1691173, 1541462, 681540, 294404], [ 323531, 303846, 352466, 218703, 111078], [ 78873, 78070, 99565, 64047, 36660], [ 282098, 295231, 323772, 167594, 78413], [ 345982, 352155, 394843, 221874, 122624], [ 555889, 524570, 521322, 249759, 105909], [ 476524, 436245, 479881, 256902, 132699], [ 255736, 235543, 260282, 132319, 57004], [ 205357, 193377, 239316, 148974, 81273], [ 579662, 562326, 638386, 384072, 199682], [ 829188, 805096, 838716, 435937, 207144]]) In [55]: l1 = [3, 6, 2] In [56]: l1 Out[56]: [3, 6, 2] In [57]: l2 = [2, 3, 7] In [58]: l2 Out[58]: [2, 3, 7] In [59]: [l1, l2] Out[59]: [[3, 6, 2], [2, 3, 7]] In [60]: hommes + femmes Out[60]: array([[ 445467, 469108, 527600, 266118, 152727], [ 741985, 756246, 905755, 546050, 353356], [ 294767, 298455, 374721, 233982, 153705], [ 351531, 326758, 399831, 241652, 159470], [ 371156, 359539, 446594, 282444, 184198], [ 789020, 741687, 877992, 518717, 332243], [ 617664, 577133, 695735, 413804, 268595], [ 322536, 317873, 361814, 206687, 124587], [ 66430, 76129, 90502, 56221, 32838], [ 288865, 280077, 317041, 181754, 110169], [ 469333, 449341, 498760, 270741, 159927], [3098719, 3468108, 3164202, 1447783, 799551], [ 633634, 618014, 730017, 461359, 284262], [ 153576, 155188, 201921, 133633, 96729], [ 549797, 580498, 654982, 352709, 212671], [ 672307, 696789, 800212, 464752, 312447], [1083581, 1053067, 1060723, 542376, 312409], [ 932434, 866618, 966434, 543388, 349477], [ 499192, 471221, 524558, 275395, 154371], [ 400250, 385451, 487784, 311493, 207181], [1132561, 1136652, 1328702, 820200, 519330], [1619020, 1615296, 1698251, 914344, 546559]]) In [61]: total = hommes + femmes In [62]: total[0][0] Out[62]: 445467 In [63]: hommes[0][0] Out[63]: 228114 In [64]: femmes[0][0] Out[64]: 217353 In [65]: total[0] Out[65]: array([445467, 469108, 527600, 266118, 152727]) In [66]: total1 = total[0] In [67]: total1 Out[67]: array([445467, 469108, 527600, 266118, 152727]) In [68]: total1.sum() Out[68]: 1861020 In [69]: total.sum() Out[69]: 63659608 In [70]: help(total.sum) In [71]: total.sum(axis=1) Out[71]: array([ 1861020, 3303392, 1355630, 1479242, 1643931, 3259659, 2572931, 1333497, 322120, 1177906, 1848102, 11978363, 2727286, 741047, 2350657, 2946507, 4052156, 3658351, 1924737, 1792159, 4937445, 6393470]) In [72]: total.sum(axis=0) Out[72]: array([15533825, 15699248, 17114131, 9485602, 5826802]) In [73]: total.sum(axis=2) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) in () ----> 1 total.sum(axis=2) ValueError: axis(=2) out of bounds In [74]: total.sum(axis=1) Out[74]: array([ 1861020, 3303392, 1355630, 1479242, 1643931, 3259659, 2572931, 1333497, 322120, 1177906, 1848102, 11978363, 2727286, 741047, 2350657, 2946507, 4052156, 3658351, 1924737, 1792159, 4937445, 6393470]) In [75]: total1.sum() Out[75]: 1861020 In [76]: Do you really want to exit ([y]/n)? zhentao@martagon:~/ipython/ipython-1.2.1$ exit exit Script done on Wed 12 Mar 2014 07:12:35 PM CET