Skip to content

Instantly share code, notes, and snippets.

@jarhoads
Created December 19, 2018 15:48
Show Gist options
  • Save jarhoads/e97a48276b12d9310eff19afd9a1e571 to your computer and use it in GitHub Desktop.
Save jarhoads/e97a48276b12d9310eff19afd9a1e571 to your computer and use it in GitHub Desktop.
numpy notes

Intro to numpy

Spyder

  • Provides an ipython environment from the IDE
    Console -> Open ipython console

ipython

  • Can use standard help function help('numpy')
  • Can get help on numpy array function help('numpy.array')
  • Import numpy with import numpy as np
  • Create numpy arrays with array1 = np.array([3, 6, 9, 12])
  • Find array data type with array1.dtype

numpy arrays

  • Create 2D array with b = np.array([[3,6,9],[2,4,6]])
  • Create zero array with c = np.zeros((5,3))
  • Create ones array with d = np.ones((3,2))
  • Find name of data type with c.dtype.name
  • Specify data type with f = np.ones((3,4), dtype=np.int64)
  • Create empty with g = np.empty((3,3))
  • Creat with range using h = np.arange(0, 10, 2)
  • Use linspace for floating point with i = np.linspace(0, 5, 13)
  • Complex numbers with cplx = np.array([[2,4],[3,6],[4,8]], dtype=complex)
  • Can use arange with reshape for building a matrix with m = np.arange(10).reshape(5,2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment