Python IV

Mary PW Chin 钱碧慧博士
PhD (Wales), MSc (Surrey)
E-mail:

1st bite of Python

Getting started

2nd bite of Python

Dice

3rd bite of Python

Circles

4th bite of Python

Statistics & histograms

5th bite of Python

More loops

6th bite of Python

Pretty nets

7th bite of Python

Jumping man

8th bite of Python

Medical scans

9th bite of Python

Handwriting recognition

10th bite of Python

Flower recognition

FOURTH BYTE OF PYTHON
a slideshow

Data files:

☞ download vancouver_mean_temp.txt

☞ download stockholm_mean_temp.txt

Synopsis
  1. Module 'matplotlib' and its 'plot' method;
  2. 'len' built-in function;
  3. Reading and splitting strings from text files;
  4. Formatted printing;
  5. String arrays;
  6. 2D arrays;
  7. Descriptive statistics: mean, min, max, variance, standard deviation;
  8. Histograms.
Do not forget

For every program you encounter it is always an excellent exercise to change the variable names to names which are most meaningful to you, then make the program run. You will gain deeper understanding of the program. You will see the program in a new light. Everyone is different: variable names most intuitive to me differ from variable names most intuitive to you. My programs are written with variable names most intuitive to me, so you should change them to names most intuitive to you so that the program flow becomes more obvious.

Exercise
  1. For program version #2, mark out the:
    • variable names;
    • arguments;
    • functions;
    • keywords;
    • modules;
    • methods.
  2. Repeat Exercise 1 with program version #5.
  3. Repeat Exercise 1 with program version #6.
  4. Repeat Exercise 1 with program version #9.
  5. Draw the flowchart for program version #5.
  6. Draw the flowchart for program version #6.
  7. Draw the flowchart for program version #9.
  8. In this lesson we made multiple revisions to the program. Summarise the improvement in each version in three columns:
    versionimprovement in plain Englishtechnical modification in Python
    #1 to #2
    #2 to #3
    #3 to #4
    #11 to #12

    versionimprovement in plain Englishtechnical modification in Python
    #13 to #14
    #17 to #18
What we have learned so far
  1. Python keywords:
    • for
    • in
    • import
    • as
    • if
    • elif
    • else
    • and
    • or
    • return
    • with
    • as
  2. Python built-in functions:
    • print(…, end='…')
    • range(…, …, …)
    • help(…)
    • dir(…)
    • int(…)
    • float(…)
    • str(…)
    • len(…)
    • range(…)
    • open(…)
  3. Python modules, methods and classes:
    • random.randint(…, …)
    • matplotlib.pyplot.Circle(…, …)
    • matplotlib.pyplot.plot(…, …)
    • matplotlib.pyplot.step(…, …)
    • matplotlib.pyplot.xlabel(…), matplotlib.pyplot.ylabel(…)
    • matplotlib.pyplot.xticks(…, …, rotation='…'), matplotlib.pyplot.yticks(…, …, rotation='…')
    • matplotlib.pyplot.xlim(…), matplotlib.pyplot.ylim(…)
    • matplotlib.pyplot.legend(…)
    • matplotlib.pyplot.savefig(…)
    • fig, ax = matplotlib.pyplot.subplots(); ax.add_artist(…); fig.savefig(…),
    • numpy.floor(…), numpy.ceil(…)
    • numpy.zeros(…,dtype='…')
    • numpy.where(…)
    • numpy.arange(…)
    • numpy.histogram(…)
    • numpy.ndarray.min(…)
    • numpy.ndarray.max(…)
    • numpy.ndarray.sum(…)
    • numpy.ndarray.astype(…)
    • file.readlines(…)
    • string.split()
  4. Linux commands (and options):
    • ls -l
    • wc -l
    • head
    • tail

☞ How to clear browser cache

1st bite of Python

Getting started

2nd bite of Python

Dice

3rd bite of Python

Circles

4th bite of Python

Statistics & histograms

5th bite of Python

More loops

6th bite of Python

Pretty nets

7th bite of Python

Jumping man

8th bite of Python

Medical scans

9th bite of Python

Handwriting recognition

10th bite of Python

Flower recognition