Python for Engineers and Scientists (v1.5)

Author

Jithender Timothy

Preface

Python is an indispensable tool for engineers and scientists due to its simplicity, versatility, and powerful libraries. This book, Python for Engineers and Scientists, aims to provide a decent introduction to Python. The contents of this book is designed to guide you through the essentials of Python. We will cover fundamental concepts, from basic syntax to advanced topics, ensuring a good foundation for further application.

Who Should Read This Book?

If you have never programmed before, this book is for you. We will start from the very basics and gradually move towards more advanced topics. If you are already familiar with Python, you can use this book as a quick reference guide.

How long will it take to complete this book?

If you are a beginner, it should take about one week to complete the book. It is recommended that you take ample breaks in between to practice the code examples and exercises. If you are already familiar with Python, you can skim through the book in a day or two.

Installation

If you are completely new to Python, then the following instructions will help you install Python in your Desktop or PC. The beginner - friendly method for learning to program with Python is using the Jupyter Notebook to write Python code. The Jupyter Notebook is a web-browser application in which Python code and normal text can be written. The file format of a Jupyter Notebook is .ipynb. Several online programming environments are also based on this format. If you have a google account, then you have free access to the google colab framework. Using google colab you can start writing programs using python directly in the browser. The following steps will help you obtain the latest version of the Jupyter Notebook on your system and you can start programming in a few minutes !

flowchart LR
    A[Download] --> B[Install]
    B --> C[Open Anaconda Navigator]
    C --> D[Launch Jupyter Notebook]

  1. Download Anacoda from the following link: https://www.anaconda.com/products/distribution#Downloads. This is a set of tools that includes Python, a set of IDEs (Interactive Development Environments) and third-party packages (to help you perform specialized computations like image processing, numerical analysis, machine learning etc.)
  2. After installation, open the Anaconda Navigator ! And launch the Jupyter Notebook application from the main page. A web browser will be initiated.
  3. If you already use Spyder or PyCharm or any other IDE (Interactive Development Environment) you can skip the next subsection !

Using the following instructions, you can create your first Jupyter Notebook !

flowchart LR
    A[New] --> B[Notebook]
    B --> C[Rename File]
    C --> D[Write code]

  1. In the Jupyter Notebook, the main page will display the root folder system. You can navigate to the folder of your choice where you want to store your Jupyter Notebooks or you can create a new folder at the location of your choice.
  2. After navigating to the folder of your choice, now you can at the top right-hand side you will find a new button. Click on that button and choose ipykernel. This will create a new Jupyter Notebook.

Jupyter notebook consists of cells. In these cells you can type in python code and normal text using Markdown. You can choose the type of cell from the dropdown menu in the menu bar. Click Help to get help on the user interface. Now write the following python code print('my first python code in Jupyter') as follows:

print('my first python code in Jupyter')
my first python code in Jupyter

If you see the above output then you have sucessfully written your first code in Jupyter using the Python language.

Alternatives to Jupyter and Anaconda

In addition to Anaconda and Jupyter, there are several other options for installing and using Python. Here are some alternatives:

  1. Official Python Distribution:
    • Download the latest version of Python from the official Python website. This method allows you to install Python directly on your system without any additional packages.
  2. Integrated Development Environments (IDEs):
    • PyCharm: A powerful IDE developed by JetBrains, PyCharm offers professional and community editions. It provides features like code completion, debugging, and an integrated terminal.
    • Visual Studio Code: A lightweight but powerful source code editor by Microsoft, which supports Python through extensions. It offers features such as IntelliSense, debugging, and Git integration.
    • Spyder: An open-source IDE specifically designed for data science and engineering. It integrates well with scientific libraries like NumPy, SciPy, and Matplotlib.
  3. Python Distributions for Scientific Computing:
    • Miniconda: A smaller, lightweight alternative to Anaconda, Miniconda allows you to install only the packages you need. It is suitable for creating a customized Python environment.
    • WinPython: A portable distribution of Python for Windows, designed for scientific and educational usage. It includes a wide range of useful libraries and tools.
  4. Online Python Environments:
    • Google Colab: A free, cloud-based Jupyter notebook environment provided by Google. It is especially useful for collaborative projects and running code without any local setup.
    • Binder: An open-source service that allows you to create sharable, interactive, and reproducible Python environments from GitHub repositories.
    • Kaggle Kernels: Online notebooks provided by Kaggle, which come pre-configured with many popular data science libraries and free GPU support.

These alternatives offer various advantages depending on your specific needs and preferences. Whether you prefer a lightweight setup or a comprehensive IDE, you can choose the option that best fits your workflow.

Further Reading

  1. Python: https://www.python.org
  2. Anaconda Tutorials: https://docs.anaconda.com/free/navigator/tutorials/index.html
  3. Jupyter: https://docs.jupyter.org/en/latest/