Scientific Computing with Python using NumPy

Launch Binder  Open in Colab  Download Notebook  View on Github  Download Zip  Download TarGz  last updated

A Tufts University Data Lab Workshop
Written by Uku-Kaspar Uustalu

datalab.tufts.edu  @TuftsDataLab

Slides: tufts.box.com/v/numpy-slides
Live offerings: go.tufts.edu/workshops
Contact: datalab-support@elist.tufts.edu


Table of Contents


Workshop Overview

This hands-on interactive workshop introduces you to scientific computing in Python and demonstrates how to work with matrices and multidimensional arrays using the popular NumPy library. The workshop is intended for those with some previous Python experience and draws comparisons between NumPy and alternatives like MATLAB, C/C++, and Fortran. The workshop notebook is suitable for self-guided study and covers the following:

The notebook is designed to be run in a pre-configured cloud-computing environment either via Binder or Google Colab and does not require the installation of any software. Use of Binder is recommended as it provides a JupyterLab interface and allows for an experience similar to using a local installation. It is also possible to run the workshop notebook using a local Anaconda or Mambaforge installation. Instructions on how to install Anaconda or Mambaforge are available here: go.tufts.edu/installingPython


Running the Workshop Notebook using a Virtual JupyterLab Instance (Recommended)

Launch Binder

  1. Click on the Launch Binder button above.
  2. A Binder instance will launch in a new tab with the message Starting Repository.
  3. Wait patiently and do not close the Binder tab. After a few minutes, a JupyterLab instance will launch.
  4. If the workshop notebook does not automatically open, double-click on intro-numpy.ipynb in the file browser on the left.

Running the Workshop Notebook using Google Colab

Open in Colab

  1. Click on the Open in Colab button above. The Google Colab interface will open in a new tab.
  2. If you are not already signed into your Google account, click on Sign In in the upper-right and sign in with your Google credentials. You must be signed in with a Google account to be able to run notebooks in Google Colab.
  3. Optional: To retain any changes you make to this notebook, save a copy of the notebook to your Google Drive by clicking the Copy to Drive button or selecting File > Save a copy in Drive. This will save the notebook to the Colab Notebooks directory in your Google Drive. Once the saved copy pops up, close the original notebook and use the copy going forward. Feel free to rename the copy if desired. Any changes made to your personal copy will be automatically saved.

You might also see a message warning you that this notebook was not authored by Google and hence might contain malicious code. You can trust Data Lab notebooks, so click Run Anyway. But when running other third-party notebooks, you should review the code beforehand.


Running the Workshop Notebook using a Local Anaconda Installation

Download Notebook

  1. Click on the Download Notebook button above to download the workshop notebook.
  2. Create a designated directory for this workshop and move the downloaded intro-numpy.ipynb notebook there.
  3. Launch Anaconda Navigator via the Start Menu (Windows) or from Applications (macOS).
    • Windows: Start > Anaconda3 > Anaconda Navigator
    • macOS: Applications > Anaconda Navigator
  4. Launch JupyterLab using the corresponding Launch button.
  5. JupyterLab will launch in a web browser. (A new tab will be generated if a browser is already open.)
  6. Within the JupyterLab file explorer on the left, navigate to the directory containing the intro-numpy.ipynb notebook.
  7. Once you are in the correct directory, double-click on intro-numpy.ipynb in the file browser to open the workshop notebook.

Running the Workshop Notebook using a Local Mambaforge Installation

Download Zip  Download TarGz

  1. Launch Terminal (macOS/Linux) or Mambaforge Prompt (Windows).
    • Windows: Start > Mambaforge > Mambaforge Prompt
    • macOS: Applications > Utilities > Terminal
  2. Run the following commands by typing or pasting the command into the console and then pressing Enter or Return.
    • Download and extract the workshop materials:
      curl -Lo - https://github.com/tuftsdatalab/intro-numpy/archive/workshop.tar.gz | tar -xzf -
    • Navigate into the extracted directory: cd intro-numpy-workshop
    • Create a new environment for the workshop: mamba env create -f environment.yml
    • Activate the workshop environment: conda activate intro-numpy
    • Open the workshop notebook in JupyterLab: jupyter lab intro-numpy.ipynb
  3. JupyterLab will launch in a web browser. (A new tab will be generated if a browser is already open.)
  4. If the workshop notebook does not automatically open, double-click on intro-numpy.ipynb in the file browser on the left.
  5. Do not close the console! Closing the console will also terminate JupyterLab. Leave the console running in the background.