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

Numpy Cheatsheet

This document is a cheatsheet for NumPy, covering essential functions for importing, creating, and manipulating arrays. It includes details on array properties, reshaping, indexing, arithmetic operations, aggregations, conditionals, and saving/loading data. The document serves as a quick reference for common NumPy tasks and operations.

Uploaded by

anjan dey
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)
2 views2 pages

Numpy Cheatsheet

This document is a cheatsheet for NumPy, covering essential functions for importing, creating, and manipulating arrays. It includes details on array properties, reshaping, indexing, arithmetic operations, aggregations, conditionals, and saving/loading data. The document serves as a quick reference for common NumPy tasks and operations.

Uploaded by

anjan dey
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
You are on page 1/ 2

NumPy Cheatsheet

IMPORTING NUMPY
import numpy as np

CREATING ARRAYS
np.array([1, 2, 3])
np.zeros((2,3))
np.ones((3,2))
np.eye(3) # Identity matrix
np.arange(0, 10, 2)
np.linspace(0, 1, 5)
np.random.rand(2,3) # Random 2x3 array

ARRAY PROPERTIES
a.shape # Dimensions
a.size # Total elements
a.dtype # Data type

RESHAPING / TRANSFORMING
a.reshape((3,2))
a.ravel() # Flatten
a.T # Transpose

INDEXING / SLICING
a[0] # First element
a[1:3] # Slice
a[1][0] or a[1, 0] # Element access

ARITHMETIC OPERATIONS
a+b
a-b
a*2
np.dot(a, b) # Matrix multiplication

AGGREGATIONS
a.sum(), a.min(), a.max()
a.mean(), a.std()

CONDITIONALS
a[a > 2] # Filter elements
np.where(a > 2, 1, 0) # Replace based on condition

SAVING / LOADING
np.save("data.npy", a)
b = np.load("data.npy")

You might also like