Differences between revisions 4 and 5
Revision 4 as of 2008-10-30 10:36:03
Size: 2383
Editor: anonymous
Comment:
Revision 5 as of 2008-10-30 10:42:22
Size: 2396
Editor: anonymous
Comment:
Deletions are marked like this. Additions are marked like this.
Line 123: Line 123:
Install python on your computer and read through the tutorial which comes with the documentation. There are translations in other languages: Install python and ipython on your computer and read through the tutorial which comes with the documentation. There are translations in other languages:
 

For loops

a)

   1 for ...:
   2      print i
   3   
   4 0
   5 1 
   6 2
   7 3
  • Insert an expression in ... to get the results.

Solution

b)

   1 for ... in zip(range(0,4,1),range(4,0,-1)):
   2      print i,j
   3   
   4 0 4
   5 1 3
   6 2 2
   7 3 1
  • Insert an expression in ... to get the results.

Solution

c)

0 0
0 1
0 2
0 3
1 0
1 1
1 2
1 3
2 0
2 1
2 2
2 3
3 0
3 1
3 2
3 3
  • What are the corresponding loops?

Solution

Scipy numeric types

from scipy import *

One byte consists of eight bit and covers the value range of 0..255 (uint8, unsigned integer) or -128..127.

   1 b=int8(128)
   2 -128 # Invalid range
   3 
   4 b.nbytes
   5 1

a)

What is the value range of the following types and how many bytes are allocated in the memory?

  • bool8
  • uint8, int8
  • uint16, int16
  • uint32, int32
  • uint64, uint64

Solution

b)

How many bytes are allocated in the memory by these floating point types?

  • float32, float64, float96
  • complex64, complex128, complex192

Solution

Data structures

a)

   1 D={'A':array(range(10)),'B':array(range(10))+1}
  • Which keys contains the dictionary D

  • Get the keys with the method D.keys()

  • Display array A

  • Display the elements 3:6 of arrays B

  • Set this elements to 0
  • Insert a new key-values pair C:array(range(0,10,-1)) into D

  • Display all values of D using the method .values()

Solution

Reading and practicing

Install python and ipython on your computer and read through the tutorial which comes with the documentation. There are translations in other languages:

LehreWiki: Python/Exercise2 (last edited 2008-11-17 14:23:55 by KorFreier)