This is a draft cheat sheet. It is a work in progress and is not finished yet.
Getting started
|
Import Numpy using np
as alias |
|
Numpy version |
|
Display all contents of the numpy namespace |
|
Display Numpy built-in documentation |
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 allocation), 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 represent). Here PyObject_HEAD
is the part of the structure containing the info mentioned above.
A Python list more than just a list
L = list(range(10))
to create a list of integers.
L2 = [True, "2", 3.0, 4]
to create a heterogeneous lists
But to allow these flexible types, each item in the list must contain its own type info, reference count, and other information–that is, each item is a complete Python object. In the special case that all variables are of the same type, much of this information is redundant: it can be much more efficient to store data in a fixed-type array ( Numpy)
|
|
|
|
|