Show Menu

Python for Data Science - Numpy Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Getting started

import numpy as np
Import Numpy using np as alias
Numpy version
Display all contents of the numpy namespace
Display Numpy built-in docume­ntation

A Python integer is more than just an integer

When we define an integer in Python, such as x = 1, x is not just a "­raw­" integer. It's actually a pointer to a compound C structure, which contains several values ob_refcnt (a reference count that helps Python handle memory alloca­tion), ob_type(the type of the variable), ob_size(the size of the following data members), ob_digit(the actual integer value the Python variable to repres­ent). Here PyObje­ct_HEAD is the part of the structure containing the info mentioned above.

A Python list more than just a list

L = list(r­ang­e(10)) to create a list of integers.
L2 = [True, "­2", 3.0, 4] to create a hetero­geneous lists

But to allow these flexible types, each item in the list must contain its own type info, reference count, and other inform­ati­on–that is, each item is a complete Python object. In the special case that all variables are of the same type, much of this inform­ation is redundant: it can be much more efficient to store data in a fixed-type array (Numpy)