Numpy
Numpy
www.intellipaat.com
Linear algebra library in Python
Used for performing mathematical and logical
operations on Arrays
Numpy?
www.intellipaat.com
How to create Numpy Array?
www.intellipaat.com
Creating Numpy Array
1D Array
Creating
Numpy Array 2D Array
www.intellipaat.com
Ndarray Object
What is
Items can be accessed using a zero-based index
Every item in an ndarray takes the same size of block
Numpy Array in the memory.
Each element in ndarray is an object of data-type
object (called dtype).
www.intellipaat.com
How shall I
initialize the
numpy array?
www.intellipaat.com
Initializing Numpy Array
Initializing
Numpy Array Arranging the numbers between x and y with an interval of z
www.intellipaat.com
Initializing Numpy Array
Initializing
Numpy Array
www.intellipaat.com
Initializing Numpy Array
Initializing
Numpy Array
Filling RANDOM numbers in a array of dimension x X y
www.intellipaat.com
How to inspect
the created
array using
numpy?
www.intellipaat.com
ndarray.shape
Inspection
www.intellipaat.com
ndarray.shape
Inspection
www.intellipaat.com
ndarray.shape
Inspection
www.intellipaat.com
ndarray.size
Inspection
www.intellipaat.com
ndarray.ndim
Numpy Array
Inspection
www.intellipaat.com
ndarray.dtype
Numpy Array
Inspection
www.intellipaat.com
Can we
perform some
mathematical
function using
numpy?
www.intellipaat.com
Addition using Numpy
Numpy Array
Mathematics
www.intellipaat.com
Other similar operations that you can perform:
np.subtract(a,b) #a-b
np.divide(a,b) #a/b
np.sqrt(a)
np.sin(a)
np.cos(a)
np.log(a)
www.intellipaat.com
Array Comparison
Element-wise Comparison
Numpy Array
Mathematics
Array-wise Comparison
www.intellipaat.com
Aggregate Functions
Numpy Array
Mathematics
www.intellipaat.com
Aggregate Functions
Numpy Array
Mathematics
www.intellipaat.com
Concept of Broadcasting
Numpy
Broadcasting
www.intellipaat.com
How to select
certain
elements from
the array?
www.intellipaat.com
Indexing in Python
Indexing and
Slicing
www.intellipaat.com
Slicing
0 1 2
0
1 2 3
Numpy 1 4 5 6
Indexing and 2 7 8 9
Slicing Let’s learn to extract/slice the array
www.intellipaat.com
Slicing
0 1 2
0
1 2 3
Numpy 1 4 5 6
Indexing and 2 7 8 9
Slicing How to extract the selected element?
www.intellipaat.com
Slicing
0 1 2
0
1 2 3
Numpy 1 4 5 6
Indexing and 2 7 8 9
Slicing How to extract the selected element?
www.intellipaat.com
Slicing
0 1 2
0
1 2 3
Numpy 1 4 5 6
Indexing and 2 7 8 9
Slicing How to extract the selected element?
www.intellipaat.com
Slicing
0 1 2
0
1 2 3
Numpy 1 4 5 6
Indexing and 2 7 8 9
Slicing How to extract the selected element?
www.intellipaat.com
Slicing
Numpy
Indexing and
Slicing
www.intellipaat.com
What are the
various
manipulations
done within the
array?
www.intellipaat.com
Concatenating two arrays together
Array
Manipulation Stack arrays column-wise(horizontally)
www.intellipaat.com
Splitting Arrays
Array
Manipulation
www.intellipaat.com
Why should
I use Numpy
if I already
have a list?
www.intellipaat.com
Why should I
use Numpy if
I already have
a list?
www.intellipaat.com
What are the advantages of Numpy over List?
Advantages
of Numpy
over List
Consumes Faster More
Less Memory Convenient
www.intellipaat.com
What are the advantages of Numpy over List?
Advantages
of Numpy
over List Pointers
1 element = 4 bytes
1 Object = 14bytes
www.intellipaat.com
Numpy vs List: Memory Size
Advantages
of Numpy
over List
www.intellipaat.com
Numpy vs List: Speed
Advantages
of Numpy
over List
www.intellipaat.com
www.intellipaat.com
India : +91-7847955955
www.intellipaat.com