PythonQ 240-8XX Instrukcja Użytkownika Strona 23

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 37
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 22
c
! www.simula.no/˜hpl
More useful array met hods and attributes
>>> a = zeros(4) + 3
>>> a
array([ 3., 3., 3., 3.]) # float data
>>> a.item(2) # more efficient than a[2]
3.0
>>> a.itemset(3,-4.5) # more efficient than a[3]=-4.5
>>> a
array([ 3. , 3. , 3. , -4.5])
>>> a.shape = (2,2)
>>> a
array([[ 3. , 3. ],
[3.,-4.5]])
>>> a.ravel() # from multi-dim to one-dim
array([ 3. , 3. , 3. , -4.5])
>>> a.ndim # no of dimensions
2
>>> len(a.shape) # no of dimensions
2
>>> rank(a) # no of dimensions
2
>>> a.size # total no of elements
4
>>> b = a.astype(int) # change data type
>>> b
array([3, 3, 3, 3])
Numerical Python – p. 257/728
Przeglądanie stron 22
1 2 ... 18 19 20 21 22 23 24 25 26 27 28 ... 36 37

Komentarze do niniejszej Instrukcji

Brak uwag