𝔖 Scriptorium
✦   LIBER   ✦

πŸ“

An Introduction to Python for Computational Science and Engineering

✍ Scribed by Hans Fangohr


Publisher
Independently Published
Year
2022
Tongue
English
Leaves
265
Category
Library

⬇  Acquire This Volume

No coin nor oath required. For personal study only.

✦ Synopsis


Readers looking for a beginner's guide to Python are faced with a bafflingarray of choices. However, Introduction to Python for Computational Science and Engineering, by Hans Fangohr is uniquely valuable because it is specifically aimed at those of us who are engaged in applied science or scientific research. The book is concise, well organized and full of practical examples that the reader can implement as they are going along. The key concepts of programming are introduced in the first half of the book, while the second half focuses on science/engineering applications: numerical methods, optimization, scientific plotting, and data science. This book is a must-have companion for anyone learning to use Python to enable their work in applied science or scientific research." - Simon Box, Head of Virtual Development at Aurora Innovation.

✦ Table of Contents


Introduction
Computational Modelling
Introduction
Computational Modelling
Programming to support computational modelling
Why Python for scientific computing?
Optimisation strategies
Get it right first, then make it fast
Prototyping in Python
Literature
Recorded video lectures on Python for beginners
Python tutor mailing list
Python version
These documents
The %%file magic
The ! to execute shell commands
The #NBVAL tags
Your feedback
A powerful calculator
Python prompt and Read-Eval-Print Loop (REPL)
Calculator
Integer division
How to avoid integer division
Why should I care about this division problem?
Mathematical functions
Variables
Terminology
Impossible equations
The += notation
Data Types and Data Structures
What type is it?
Numbers
Integers
Integer limits
Floating Point numbers
Complex numbers
Functions applicable to all types of numbers
Sequences
Sequence type 1: String
Sequence type 2: List
The range() command
Sequence type 3: Tuples
Indexing sequences
Slicing sequences
Dictionaries
Passing arguments to functions
Call by value
Call by reference
Argument passing in Python
Performance considerations
Inadvertent modification of data
Copying objects
Equality and Identity/Sameness
Equality
Identity / Sameness
Example: Equality and identity
Introspection
dir
Magic names
type
isinstance
help
Docstrings
Input and Output
Printing to standard output (normally the screen)
Simple print
Formatted printing
β€œstr” and β€œstr”
β€œrepr” and β€œrepr”
New-style string formatting
Changes from Python 2 to Python 3: print
Reading and writing files
File reading examples
fileobject.read()
fileobject.readlines()
Iterating over lines (file object)
Further reading
Control Flow
Basics
Conditionals
If-then-else
For loop
While loop
Relational operators (comparisons) in if and while statements
Exceptions
Raising Exceptions
Exception hierarchy
Creating our own exceptions
LBYL vs EAFP
Functions and modules
Introduction
Using functions
Defining functions
Default values and optional parameters
Modules
Importing modules
Creating modules
Use of name
Example 1
Example 2
Further Reading
Functional tools
Anonymous functions
Map
Filter
List comprehension
Reduce
Why not just use for-loops?
Speed
The %%timeit magic
Common tasks
Many ways to compute a series
Sorting
Efficiency
From Matlab to Python
Important commands
The for-loop
The if-then statement
Indexing
Matrices
Python shells
IDLE
Python (command line)
Interactive Python (IPython)
IPython console
Jupyter Notebook
Spyder
Editors
Symbolic computation
SymPy
Output
Symbols
isympy
Numeric types
Differentiation and Integration
Ordinary differential equations
Series expansions and plotting
Linear equations and matrix inversion
Non linear equations
Output: LaTeXΒ interface and pretty-printing
Automatic generation of C code
Related tools
Numerical Computation
Numbers and numbers
Limitations of number types
Limitations of ints
Limitations of floats
Limitations of complex numbers
…are these number types of practical value?
Using floating point numbers (carelessly)
Using floating point numbers carefully 1
Using floating point numbers carefully 2
Symbolic calculation
Summary
Exercise: infinite or finite loop
Numerical Python (numpy): arrays
Numpy introduction
History
Arrays
Vectors (1d-arrays)
Matrices (2d-arrays)
Convert from array to list or tuple
Standard Linear Algebra operations
Maxtrix multiplication
Solving systems of linear equations
Computing Eigenvectors and Eigenvalues
Curve fitting of polynomials
More numpy examples…
Numpy for Matlab users
Visualising Data
Matplotlib – plotting y=f(x), (and a bit more)
Matplotlib and Pylab
First example
The pyplot interface
How to import matplotlib, pylab, pyplot, numpy and all that
The Pylab interface
IPython’s inline mode
Saving the figure to a file
The pylab interface
Fine tuning your plot
Plotting more than one curve
Two (or more) curves in one graph
Two (or more graphs) in one figure window
Two (or more) figure windows
Interactive mode
The matplotlib.pyplot interface
Histograms
Visualising matrix data
What colour map to choose?
Plots of z = f(x, y) and other features of Matplotlib
How to learn how to use Matplotlib?
Visual Python
Basics, rotating and zooming
Setting the frame rate for animations
Tracking trajectories
Connecting objects (Cylinders, springs, …)
3d vision
Visualising higher dimensional data (VTK)
Mayavi, Paraview, Visit
Writing vtk files from Python (pyvtk)
Further tools and developments
Exploiting self-describing data for visualisation
The future of data visualisation
Fine-tuning matplotlib plots that are generated by high level frame works
Jupyter Notebooks
Numerical Methods using Python (scipy)
Overview
SciPy
Numerical integration
Exercise: integrate a function
Exercise: plot before you integrate
Solving Ordinary Differential Equations (ODEs)
Systems of coupled ODEs
Root finding
Root finding using the bisection method
Exercise: root finding using the bisect method
Root finding using the fsolve funcion
Interpolation
Curve fitting
Fourier transforms
Optimisation
Other numerical methods
scipy.io: Scipy-input output
Pandas - Data Science with Python
Motivational example (Series)
Pandas Series
Stock example - Series
memory usage
Statistics
Create Series from list
Plotting data
Missing values
Series data access: explicit and implicit (loc and iloc)
Indexing
Slicing
Data manipulation
Import and Export
Data Frame
Stock Example - DataFrame
Accessing data in a DataFramea
Extracting columns of data
Extracting rows of data
Data manipulation with shop
Example: European population 2017
Further reading
Python packages and environments
Introduction
Shell commands in the Jupyter notebook
Prerequisits
Python virtual environments
Creating virtual enviroments
Activating a virtual environment
Using the virtual environment
Name of the virtual environment
Python Package Index (PyPI)
Installing packages with pip
Learn more about an installed package using pip show
Uninstalling packages with pip
Installing packages with additional dependencies
Installing particular versions with pip
Upgrading a pip-installed package
Installing a package from github
Pip install a user-editable package from a local directory
Advance pip use: freeze, -r requirements.txt and creating reproducible environments
Deactivate a virtual environment
Deleting a virtual enviroment
Further reading
Anaconda
Introduction
Can I use Python virtual environments when using the anaconda distribution?
Should I install a python package through conda or pip?
Can I create a conda environment, and then create python virtual environments from this?
Managing many different environments - pyenv
Where to go from here?
Advanced programming
Compiled programming language
Testing
Simulation models
Software engineering for research codes
Data and visualisation
Version control
Parallel execution
Acknowledgements
Change history


πŸ“œ SIMILAR VOLUMES


Computing with Python: An Introduction t
✍ Claus Feuhrer πŸ“‚ Library πŸ“… 2013 πŸ› Pearson 🌐 English

Python(r) is a free open-source language and environment that has tremendous potential in the scientific computing domain. Computing with Python presents the programming language in tight connection with mathematical applications. The approach of the book is concept based rather than a systematic in

Computing with Python: An Introduction t
✍ Feuhrer, Claus πŸ“‚ Library πŸ“… 2013 πŸ› Pearson 🌐 English

Python(r) is a free open-source language and environment that has tremendous potential in the scientific computing domain. Computing with Python presents the programming language in tight connection with mathematical applications. The approach of the book is concept based rather than a systematic in

Computing With Python An Introduction t
✍ Claus Fuher πŸ“‚ Library πŸ“… 2013 πŸ› Pearson 🌐 English

Python is a free open-source language and environment that has tremendous potential in the scientific computing domain. Computing with Python presents the programming language in tight connection with mathematical applications. The approach of the book is concept based rather than a systematic intro

Introduction to Python for Science and E
✍ David J. Pine πŸ“‚ Library πŸ“… 2019 πŸ› CRC Press 🌐 English

Series in Computational Physics<br /><i>Steven A. Gottlieb and Rubin H. Landau, Series Editors</i><br /><br /><br /><br /><strong>Introduction to Python for Science and Engineering</strong><br /><br /><br /><br />This guide offers a quick and incisive introduction to Python programming for anyone. T