This note book has the notes for NumPy Essential Training_1_Foundations of Numpy from LinkedIn Learning.

Notes by Jinyu Du

Mar.5.2022

Link to the course is here

Course author: Terezija Semenski

NumPy is the most important package for scientific computing in Python. It is the base for many other packages. It can do things such as arithemetic operations, statistics operations, bitwise operations, copying and viewing arrays, stacking, searching, sorting, counting, mathematical operations, linear algegra, broadcasting, matrix operations.

Why NumPy?

Python lists have:

  1. no support for vectorized operations.
  2. no fixed type elements.

But NumPy arrays do:

  1. support vectorized operations.
  2. fixed data type.
  3. consume much less memory.

NumPy code is cleaner. That is, same tasks with fewer lines and fewer loops because operations work directly work on vectors and matrices. NumPy has advanced mathematical functions. Machine leaning packages use NumPy heavily. Some examples of packages that use NumPy features are SciPy, scikit learn, Pandas, matplotlib, statsmodel.

Chapter 2 NumPy array types and creating NumPy arrays

Array types and conversions between types

Notice that the value is truncated to integer. This is because in NumPy, all the data has to be of the same type.

Multidimensional arrays

A one-dimensional array is a vector.

$$\left[\begin{array}{c} 1\\ 7 \end{array}\right]$$

A two-dimensional array is a matrix.

$$\left[\begin{array}{cc} 1 & 2\\ 7 & 19 \end{array}\right]$$

A three-dimensional array is a tensor.

$$\left[\begin{array}{cc} \left[\begin{array}{cc} 1 & 2\\ 7 & 19 \end{array}\right] & \left[\begin{array}{cc} 1 & 2\\ 7 & 19 \end{array}\right]\\ \left[\begin{array}{cc} 1 & 2\\ 7 & 19 \end{array}\right] & \left[\begin{array}{cc} 1 & 2\\ 7 & 19 \end{array}\right] \end{array}\right]$$

Creating arrays from Lists and other Python structures

An NumPy array must have elements of the SAME type.

Intrisic NumPy array creation

Creating arrays filled with constant values

Finding the shape and size of an array

Chapter 3 Manipulate NumPy arrays

Adding, removing and sorting elements

Copies and views

A copy is a new array that is stored in a different memory location. View provides a different view of the original array.

Reshaping arrays

Indexing and slicing

Joining and splitting ararys

Chapter 4 Functions and operations

Arithmetic operations

Broadcasting

Aggregate functions

How to get unique items and counts

Transpose like operations

Reshape remakes the array by the inputs, while transpose swaps rows and columns of an array.

Reversing an array