This repository was archived by the owner on Jan 9, 2023. It is now read-only.
Folders and files Name Name Last commit message
Last commit date
parent directory
View all files
Introduction to NumPy and Matplotlib
More efficient
Use for large scale arrays / matrices
Convert between lists
tolist()
and np.array()
.shape
check the dimensions
.dtype
check the data type of the elements
np.zeros()
creates an array filled with 0
s of the set shape
np.arange(n)
creates an array from 0
to n-1
np.linspace(s, e, num=g)
creates an array with elements, from s
to e
linearly separated with gap size g
+
, -
, +=
, and -=
work elementwise
Boolean indexing
arr > n
Maps the array to booleans, compares them elementwise
arr[arr > n]
keeps all elements that satisfy the condition
Array stacking
np.vstack()
- stack on vertical stack
np.hstack()
- stack on horizontal stack
np.dstack()
- stack on depth stack
Array concatenation
Appends on the same axis, unlike stacking
Array splitting
Can specify splitting at what positions
np.vsplit()
- splits on vertical axis
np.hsplit()
- splits on horizontal axis
np.dsplit()
- splits on depth axis
Repeating arrays
np.repeat()
repeats items elementwise
Flattens array if no axis is specified
Nonzero searching
np.nonzero()
returns the indices in arrays
Unique filtering
np.unique()
returns the unique elements
Sorting
arr.sort()
is a mutator
np.argsort
returns the sorted indices
Saving and loading
Will save as .npz
Can also save as txt by .savetxt()
and .loadtxt()
Random
Seeding
Use rg
for functions
Print options
np.set_printoptions(threshold=x)
Prints more items up to x
You can’t perform that action at this time.