0% found this document useful (0 votes)
5 views2 pages

Numpy Cheatsheet

This document is a quick reference cheatsheet for NumPy, detailing setup, array creation, data types, reshaping, indexing, mathematical operations, matrix operations, and saving/loading data. It provides code snippets for various functionalities such as creating arrays, performing mathematical calculations, and manipulating matrix data. The cheatsheet serves as a concise guide for users to efficiently utilize NumPy in their programming tasks.

Uploaded by

rabyasana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Numpy Cheatsheet

This document is a quick reference cheatsheet for NumPy, detailing setup, array creation, data types, reshaping, indexing, mathematical operations, matrix operations, and saving/loading data. It provides code snippets for various functionalities such as creating arrays, performing mathematical calculations, and manipulating matrix data. The cheatsheet serves as a concise guide for users to efficiently utilize NumPy in their programming tasks.

Uploaded by

rabyasana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

NumPy (np) Cheatsheet – Quick Reference

Setup
import numpy as np
np.__version__

Create Arrays
a = [Link]([1, 2, 3]) # from list
b = [Link]([[1, 2], [3, 4]]) # 2D
z = [Link]((3, 4)) # zeros
o = [Link]((2, 3)) # ones
e = [Link]((2, 2)) # uninitialized
i = [Link](0, 10, 2) # [0,2,4,6,8]
l = [Link](0.0, 1.0, 5) # 5 pts 0..1
r = [Link].default_rng(42) # generator
u = [Link]((2, 3)) # uniform [0,1)
n = [Link](loc=0, scale=1, size=(3,)) # normal

Dtype & Shape


[Link] # data type
[Link] # dimensions (rows, cols)
[Link] # number of dimensions
[Link] # total elements
[Link] # bytes per element

Reshape & Combine


[Link](2, 3)
[Link]((a, b)) # vertical stack
[Link]((a, b)) # horizontal stack
[Link]([a,b], axis=0)

Indexing & Slicing


a[0], a[-1], a[1:3]
a[:,0] # first column
a[1,:] # second row
a[::2] # step slicing
a[a > 5] # boolean indexing

Math & Stats


[Link](a, b)
[Link](a, b)
[Link](a, b)
[Link](a, b)
[Link](a), [Link](a), [Link](a)
[Link](a), [Link](a), [Link](a)
[Link](a), [Link](a), [Link](a)

Matrix Ops
[Link](a, b)
a.T # transpose
[Link](b) # inverse
[Link](b) # determinant
[Link](b) # eigenvalues/vectors

Save & Load


[Link]('[Link]', a)
[Link]('[Link]')
[Link]('[Link]', a)
[Link]('[Link]')

You might also like