0% found this document useful (0 votes)
562 views

Python NumPy Cheat Sheet

Python NumPy is a library for working with multidimensional arrays and matrices in Python. It allows fast performance of mathematical and logical operations on large arrays. NumPy arrays, or ndarrays, provide an efficient multi-dimensional container for numeric data and allow vectorized arithmetic operations. NumPy also provides functions for reading and writing arrays from files, calculating statistics, sorting, reshaping arrays, basic linear algebra, and more.

Uploaded by

Deepak as400
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
562 views

Python NumPy Cheat Sheet

Python NumPy is a library for working with multidimensional arrays and matrices in Python. It allows fast performance of mathematical and logical operations on large arrays. NumPy arrays, or ndarrays, provide an efficient multi-dimensional container for numeric data and allow vectorized arithmetic operations. NumPy also provides functions for reading and writing arrays from files, calculating statistics, sorting, reshaping arrays, basic linear algebra, and more.

Uploaded by

Deepak as400
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

PYTHON FOR DATA •

Initial Placeholders Operations Array Mathematics

SCIENCE
np.zeros(3) - 1D array of length 3 all zeros Copying: Arithmetic Operations:
• np.copy(array) - Copies array to new memory array. • Addition: np.add(a,b)
• np.zeros((2,3)) - 2D array of all zeros • view(dtype) - Creates view of array elements with type • Subtraction: np.subtract(a,b)

CHEAT SHEET dtype


Sorting:


Multiplication: np.multiply(a,b)
Division: np.divide(a,b)
• array.sort() - Sorts array

Python NumPy
np.zeros((3,2,4)) - 3D array of all zeros • Exponentiation: np.exp(a)
• array.sort(axis=0) - Sorts specific axis of array
• Square Root: np.sqrt(b)
• array.reshape(2,3) - Reshapes array to 2 rows, 3 columns
without changing data. Comparison:
Adding: • Element-wise: a==b
• np.append(array,values) - Appends values to end of array • Array-wise: np.array_equal(a,b)
What is NumPy?
• np.insert(array,4,values) - Inserts values into array before
index 4
A library consisting of multidimensional array objects and a Functions
Removing:
collection of routines for processing those arrays.
• np.delete(array,2,axis=0) - Deletes row on index 2 of array • Array-wise Sum: a.sum()
• np.full((3,4),2) - 3x4 array with all values 2
• np.delete(array,3,axis=1) - Deletes column on index 3 of • Array-wise min value: a.min()
• np.random.rand(3,5) - 3x5 array of random floats array
Why NumPy? between 0-1 • Array row max value: a.max(axis=0)
Combining:
• np.ones((3,4)) - 3x4 array with all values 1 • Mean: a.mean()
• np.concatenate((array1,array2),axis=0) - Adds array2 as
Mathematical and logical operations on arrays can be • np.eye(4) - 4x4 array of 0 with 1 on diagonal • Median: a.median()
rows to the end of array1
performed. Also provides high performance. • np.concatenate((array1,array2),axis=1) - Adds array2 as
Saving and Loading columns to end of array1 • Learn from industry experts and be sought-after by
Splitting:
On disk: the industry!
Import Convention • np.split(array,3) - Splits array into 3 sub-arrays
• np.save("new_array",x) • Learn any technology, show exemplary skills and have
• np.load("new_array.npy") Indexing:
import numpy as np – Import numpy an unmatched career!
Text/CSV files: • a[0]=5 - Assigns array element on index 0 the value 5
• The most trending technology courses to help you
• np.loadtxt('New_file.txt') - From a text file • a[2,3]=1 - Assigns array element on index [2][3] the value 1
• np.genfromtxt('New_file.csv',delimiter=',') - From a CSV Subseting: fast-track your career!
ND Array file
• a[2] - Returns the element of index 2 in array a. • Logical modules for both beginners and mid-level
• np.savetxt('New_file.txt',arr,delimiter=' ') - Writes to a
Space efficient multi-dimensional array, which provides • a[3,5] - Returns the 2D array element on index [3][5] learners
text file
vectorized arithmetic operations. • np.savetxt('New_file.csv',arr,delimiter=',') - Writes to a Slicing:
CSV file • a[0:4] - Returns the elements at indices 0,1,2,3
Properties:
• a[0:4,3] - Returns the elements on rows 0,1,2,3 at column 3
Creating Array • array.size - Returns number of elements in array
• a[:2] - Returns the elements at indices 0,1
• array.shape - Returns dimensions of array(rows,
• a=np.array([1,2,3]) columns) • a[:,1] - Returns the elements at index 1 on all rows
• b=np.array([(1,2,3,4),(7,8,9,10)],dtype=int) • array.dtype - Returns type of elements in array FURTHERMORE:
Python for Data Science Certification Training Course

You might also like