NumPy - robbiehume/CS-Notes GitHub Wiki

Overview

  • The main function of NumPy is to work with large, multi-dimensional arrays and to perform complex mathematical operations between them
  • It has a data structure called ndarray, which is the reason behind NumPy's efficiency

General

  • Import numpy: import numpy as np

Array

  • An array is a data structure that stores a sequence of elements of the same data type
  • Arrays can be one-dimensional (a sequence of elements), two-dimensional (a grid-like structure with rows and columns), or multi-dimensional (with more than two dimensions)

Creating NumPy array

  • From list: np_array = np.array([1, 2, 3])
  • Filled list: np.zeros(size) or np.ones(size)
    • Note: this fills the array with 0. and 1. floats (not integers)
  • From range: np.arange(start, stop, step)
    • Just like with a range(), start and step are optional