PythonQ 240-8XX Instrukcja Użytkownika Strona 20

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 37
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 19
c
! www.simula.no/˜hpl
Array computat ion s
Arithmetic operations can be used with arrays:
b=3
*
a-1 #aisarray,bbecomesarray
1) compute t1 = 3
*
a,2)computet2= t1 - 1,3)setb=t2
Array operations are much faster than element-wise operations:
>>> import time # module for measuring CPU time
>>> a = linspace(0, 1, 1E+07) # create some array
>>> t0 = time.clock()
>>> b = 3
*
a-1
>>> t1 = time.clock() # t1-t0 is the CPU time of 3
*
a-1
>>> for i in xrange(a.size): b[i] = 3
*
a[i] - 1
>>> t2 = time.clock()
>>> print ’3
*
a-1: %g sec, loop: %g sec’ % (t1-t0, t2-t1)
3
*
a-1: 2.09 sec, loop: 31.27 sec
Numerical Python – p. 254/728
Przeglądanie stron 19
1 2 ... 15 16 17 18 19 20 21 22 23 24 25 ... 36 37

Komentarze do niniejszej Instrukcji

Brak uwag