Numpy
Numpy
NUMPY
BY HARSH BANSAL AND AKSHAT MANGAL
WHAT IS NUMPY?
• NumPy is a Python library used for working with arrays.
• It also has functions for working in domain of linear algebra, fourier
transform, and matrices.
WHY NUMPY NOT LIST ?
• In Python we have lists that serve the purpose of arrays, but they are
slow to process.
• NumPy aims to provide an array object that is up to 50x faster than
traditional Python lists.
• NumPy arrays are stored at one continuous place in memory unlike
lists, so processes can access and manipulate them very efficiently.
• This is the main reason why NumPy is faster than lists. Also it is
optimized to work with latest CPU architectures.
NUMPY CREATING ARRAYS
type(): This built-in Python function tells us the type of the object passed to it. Like in above code it shows
that arr is numpy.ndarray type.
• Create a 2-D array containing two arrays with the values 1,2,3 and 4,5,6:
Code:
Output:
NUMPY ARRAY FUNCTIONS
Output:
NUMPY ARRAY FUNCTIONS
np.reshape()
:
NUMPY ARRAY SLICING
Slicing in python means taking elements from one given index to another
given index.
We pass slice instead of index like this: [start:end].
We can also define the step, like this: [start:end:step].
If we don't pass start its considered 0
If we don't pass end its considered length of array in that dimension
If we don't pass step its considered 1
• Example: Output
NUMPY OPERATIONS
Addition
Subtraction
Multiplication
Divison
NUMPY OPERATION