Python Programming and Numerical Methods Overview

https://www.elsevier.com/books/python-programming-and-numerical-methods/kong/978-0-12-819549-9

A book recommended on Zhihu, published by Cambridge University Press, titled 'Numerical Methods in Engineering with Python', covers fundamental topics such as numerical algebra, curve fitting, root finding, numerical differential equations, and a bit of optimization, suitable for engineers.

Chapter 1. Python Fundamentals

1.1 Setting Up the Python Environment

It is advised to use Anaconda or Miniconda to install and manage packages.

  1. Conda is a package and environment management tool that can manage packages and isolate different versions of Python environments, similar to nvm for managing Node.js environments.
  2. Anaconda and Miniconda are both distributions of conda, differing mainly in the number of packages they include.
  3. Anaconda includes over 180 scientific packages and their dependencies, making it large but comprehensive. Miniconda is a minimal version containing only conda, Python, pip, zlib, and some other common packages.
  4. Pip is a package manager that only manages Python packages, while conda can manage packages for all languages and also manage Python environments.
  5. Miniconda operations are done via the command line without a GUI, whereas Anaconda has a graphical interface.

Download Anaconda from the official site or use the Tsinghua University mirror: https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

Install Miniconda and configure environment variables as needed.

Configure the Tsinghua source to speed up conda downloads:

  1. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  2. conda config --set show_channel_urls yes

Use conda list to view installed packages.

Step 3: Install Required Packages

Install ipython, numpy, scipy, pandas, matplotlib, and jupyter notebook using conda install commands.

Running Python Code

  • Use Python shell or Ipython shell
  • Run .py scripts from the command line
  • Use Jupyter Notebook

Jupyter Notebook allows writing and running code directly in a web browser, displaying results inline. It supports Markdown for documentation and LaTeX for mathematical expressions.

The Zen of Python

import this outputs a text describing The Zen of Python by Tim Peters.

1.2 Using Python as a Calculator

Python can handle infinity, represented as math.inf, and operations like math.inf/math.inf result in nan.

Basic data types:

  • int: Integers like 1, 2, 3
  • float: Floating-point numbers like 3.2, 6.4
  • complex: Complex numbers like 2 + 5j (note that j is used instead of i)

Use type() function to check data types.

1.3 Managing Packages

Pip is a common method for installing Python packages.

pip help pip install package_name pip install package_name==1.5 pip install --upgrade package_name pip uninstall package_name pip list pip show package_name

Conda serves a similar purpose to pip.

Source code installation involves using setup.py:

python setup.py install

1.4 Introduction to Jupyter Notebook

Start with jupyter notebook command.

1.5 Logical Expressions and Operators

Tags: python Numerical Methods Jupyter Notebook Package Management programming

Posted on Mon, 31 Aug 2026 16:23:34 +0000 by afrim12