NUMPY & APPLICATIONS
i
INTRODUCTION TO NUMPY
NumPy is a library for the Python programming
language, adding support for large, multi-
dimensional arrays and matrices, along with a
large collection of high-level mathematical
functions to operate on these arrays.
LISTS VS NUMPY
Python Lists NumPy Arrays
The list can be homogeneous or Array are by default homogeneous
heterogeneous.
Elements of an array are stored
Elements of a list need not be contiguously in memory and memory
contiguous in memory. efficient
Element wise operation is not possible Element wise operation is possible
PYTHON LISTS VS NUMPY ARRAYS (DATA TYPES)
1
MEMORY ALLOCATION
ELEMENT WISE OPERATION
2
SOLD IN SHOP (IN KG)
APPLE BANANA ORANGE
20 22 35
• Bonus For The Employee
• Up To 10kg: No Bonus
• Above 10 Kgs, Each Kg Rs. 20
LISTS VS NUMPY-PRACTICALS
• Creation Of List And Data Type
• Creation Of Numpy Array And Data Type
• Different Ways Of Creating Numpy Arrays
• Checking Data Types (Python Lists Vs Numpy Arrays)
• Element Wise Operations
• Speed Check
NUMPY ADVANTAGES
• Consumes less memory.
• Very fast as compared to the python List.
• Many mathematical methods
NUMPY BASICS
Numpy.Arange ()
Numpy.Linspace()
Numpy.Zeros()
Numpy.Ones()
Numpy.Full()
Reshape
3
RESHAPE
Sales Input File Is Updated Column Wise Everyday (For One Week),
And Final File Look Like
Sales In Kgs
Monday Tuesday Wednesday Thursday Friday
Apple Banana Apple Banana Apple Banana Apple Banana Apple Banana
20 25 15 21 16 24 23 27 18 22
In similar lines for Price input file is updated column wise and final
file look like
Price in INR
Monday Tuesday Wednesday Thursday Friday
Apple Banana Apple Banana Apple Banana Apple Banana Apple Banana
200 30 180 32 175 35 220 36 210 32
Day wise (in rows) amount calculation
Fruit wise (in rows) amount calculation
4
INDEXING & SLICING AND FUNCTIONS
• Indexing & Slicing
• Basic Math Functions
• Linear Algebra Functions
• Aggregate Functions
AXIS (restricted to 2d arrays)
5
RESHAPE AND AXIS
Sales input file is updated column wise everyday (for one week), and
final file look like
Sales in Kgs
Monday Tuesday Wednesday Thursday Friday
Apple Banana Apple Banana Apple Banana Apple Banana Apple Banana
20 25 15 21 16 24 23 27 18 22
In similar lines for Price input file is updated column wise and final
file look like
Price in INR
Monday Tuesday Wednesday Thursday Friday
Apple Banana Apple Banana Apple Banana Apple Banana Apple Banana
200 30 180 32 175 35 220 36 210 32
Day wise (in rows) amount calculation
6
Fruit wise (in rows) amount calculation
BROADCAST
BROADCASTING