PythonQ 240-8XX Instrukcja Użytkownika Strona 12

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 37
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 11
c
! www.simula.no/˜hpl
From “anything” to a NumPy array
Given an object a,
a=asarray(a)
converts a to a NumPy array (if possible/necessary)
Arrays can be ordered as in C (default) or Fortran:
a=asarray(a,order=Fortran)
isfortran(a) # returns True if a’s order is Fortran
Use asarray to, e.g., allow flexible arguments in functions:
def myfunc(some_sequence):
a=asarray(some_sequence)
return 3
*
a-5
myfunc([1,2,3]) # list argument
myfunc((-1,1)) # tuple argument
myfunc(zeros(10)) # array argument
myfunc(-4.5) # float argument
myfunc(6) # int argument
Numerical Python – p. 246/728
Przeglądanie stron 11
1 2 ... 7 8 9 10 11 12 13 14 15 16 17 ... 36 37

Komentarze do niniejszej Instrukcji

Brak uwag