Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > fr.comp.lang.python > #3030

Re: remplir un tableau

Path csiph.com!aioe.org!.POSTED!not-for-mail
From marc.marc@marc.org
Newsgroups fr.comp.lang.python
Subject Re: remplir un tableau
Date Wed, 31 Jan 2018 09:25:49 +0100
Organization Aioe.org NNTP Server
Lines 50
Message-ID <p4ruid$1jsu$1@gioia.aioe.org> (permalink)
References <5a6fa2b6$0$7180$426a74cc@news.free.fr>
NNTP-Posting-Host 75+CVavSwreFfKBdOg1Wnw.user.gioia.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
X-Complaints-To abuse@aioe.org
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0
Content-Language en-US
X-Notice Filtered by postfilter v. 0.8.2
Xref csiph.com fr.comp.lang.python:3030

Show key headers only | View raw


Bonjour,
je ne réponds pas à la question, mais pour ce genre d'opération il vaut 
bien mieux à mon avis utiliser les tableaux (arrays) numpy, sur lesquels 
on peut de plus faire toutes sortes de calculs, que les listes:

import numpy as np
import pylab as pl

image = np.random.randint(low=0,high=10,size=(50,50))
pl.imshow(image,cmap="gray")
pl.show()

Amicalement.
Marc





Le 29/01/2018 à 23:39, Fabrice a écrit :
> Bonjour,
> 
> je voulais remplir un tableau avec des nombres aléatoires mais j'ai 50 
> fois la même ligne !
> 
> j'ai fait :
> 
> import matplotlib.pyplot as plt
> import random
> 
> image = [[0]*50]*50
> 
> for ligne in range(50):
>      for pixel in range(50):
>          image[ligne][pixel] = random.randint(0, 10)
> 
> plt.imshow(image,cmap='gray')
> plt.show()
> 
> Pourquoi ?
> 
> Merci,
> Fabrice.
> 
> ---
> L'absence de virus dans ce courrier électronique a été vérifiée par le 
> logiciel antivirus Avast.
> https://www.avast.com/antivirus
> 

Back to fr.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

remplir un tableau Fabrice <professeur.leclercq@gmail.com> - 2018-01-29 23:39 +0100
  Re: remplir un tableau Benoit Izac <use.reply.to@INVALID.ADDRESS> - 2018-01-30 07:19 +0100
    Re: remplir un tableau Fabrice <professeur.leclercq@gmail.com> - 2018-01-31 16:15 +0100
      Re: remplir un tableau Benoit Izac <use.reply.to@INVALID.ADDRESS> - 2018-01-31 18:50 +0100
  Re: remplir un tableau Nicolas <nicolasp@aaton.com> - 2018-01-30 09:53 +0100
    Re: remplir un tableau Fabrice <professeur.leclercq@gmail.com> - 2018-01-31 16:17 +0100
  Re: remplir un tableau marc.marc@marc.org - 2018-01-31 09:25 +0100
    Re: remplir un tableau Fabrice <professeur.leclercq@gmail.com> - 2018-01-31 16:23 +0100

csiph-web