Day 5#

Overview#

In today’s class, we will introduce the NumPy library. NumPy is a powerful library that is widely used for numerical applications. Its main data structure, the NumPy array, allows for multi-dimensional arrays that can take advantage of a property called “broadcasting”. NumPy is built on C (a compiled language), so can be much faster than standard Python alone.

We then will move our code to a Python module. This will allow us to import our functions into other Python files or the Jupyter notebook.

Lessons#

Lesson Title

Objectives

Questions

Working with Numpy Arrays

  • Be able to name the differences between Python lists and numpy arrays.

  • Understand the idea of broadcasting.

  • What are the differences between NumPy arrays and lists?

  • How can I use NumPy to do calculations?

Rewriting the Distance Function

  • Rewrite calculate distance function for numpy arrays

  • How can I rewrite functions to take advantage of NumPy element-wise operation and broadcasting?

Creating a Python Module

  • Put Python code into a module (.py file)

  • Import functions from our module.

  • What is a Python module?

Discussions and Assignments#