Précédent   Forum du club des développeurs et IT Pro > Autres langages > Python & Zope > Calcul scientifique
Calcul scientifique Forum d'entraide sur la programmation scientifique et bibliothèques associées (PIL, NumPy, SciPy, ...)
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 08/01/2013, 10h31   #1
Pierre Levy
Membre du Club
 
Inscription : mars 2004
Messages : 56
Détails du profil
Informations personnelles :
Âge : 71

Informations forums :
Inscription : mars 2004
Messages : 56
Points : 42
Points : 42
Par défaut Numpy et fractale de Mandelbrot

Bonjour à toutes et à tous et bonne année

J'ai trouvé dans le livre "Numpy cookbook" le code suivant pour dessiner l'ensemble de Mandelbrot.

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- coding: utf-8 -*-
import numpy
import matplotlib.pyplot
 
import sys
 
if(len(sys.argv) != 2):
  print "Please input the number of  iterations for the fractal"
  sys.exit()
ITERATIONS = int(sys.argv[1])
SIZE=1024
MAX_COLOR = 255.
x_min, x_max = -2.5, 1
y_min, y_max = -1.75, 1.75
# Initialize arrays
x, y = numpy.meshgrid(numpy.linspace 
  (x_min, x_max, SIZE),  
  numpy.linspace(y_min, y_max, SIZE))
c = x + 1j * y
z = c.copy()
fractal = numpy.zeros(z.shape,  
  dtype=numpy.uint8) + MAX_COLOR
# Generate fractal
for n in range(ITERATIONS):
#    print n
    mask = numpy.abs(z) <= 4 
    z[mask] = z[mask] ** 2 +  c[mask]
    fractal[(fractal == MAX_COLOR) &  
      (-mask)] = (MAX_COLOR - 1) * n / ITERATIONS
# Display the fractal
matplotlib.pyplot.imshow(fractal)
matplotlib.pyplot.title('Mandelbrot')
matplotlib.pyplot.axis('on')
matplotlib.pyplot.colorbar()
matplotlib.pyplot.axis('off')
matplotlib.pyplot.title('Mandelbrot')
matplotlib.pyplot.show()
Ce code fonctionne parfaitement et me semble très efficace mais j'ai un gros problème de compréhension de la boucle for et en particulier des lignes 28 et 29.

Si une âme charitable et experte pouvait m'expliquer je l'en remercie par avance.
Pierre Levy est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 12h33.


 
 
 
 
Partenaires

Hébergement Web