PythonQ 240-8XX Manuel d'utilisateur Page 18

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 37
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 17
c
! www.simula.no/˜hpl
Loops over arrays (1)
Standard loop over each element:
for i in xrange(a.shape[0]):
for j in xrange(a.shape[1]):
a[i,j] = (i+1)
*
(j+1)
*
(j+2)
print ’a[%d,%d]=%g % (i,j,a[i,j]),
print # newline after each row
Astandardforloopiteratesoverthefirstindex:
>>> print a
[[ 2. 6. 12.]
[4.12.24.]]
>>> for e in a:
... print e
...
[2. 6.12.]
[4.12.24.]
Numerical Python – p. 252/728
Vue de la page 17
1 2 ... 13 14 15 16 17 18 19 20 21 22 23 ... 36 37

Commentaires sur ces manuels

Pas de commentaire