Prof.
Manjusha Tatiya
Dr. Deepak Dharrao
Prof.Deepali Dhadwad
Indira College of Engineering Management, Pune
CONTENT
• What is NumPy?
• Why NumPy?
• Where is NumPy used?
• NumPy Operations
• Data Analysis of Cab Ride of New York city.
Monday, September 18, 2023 Indira College of Engineering Management, Pune
What is NumPy?
• NumPy is a Python package that stands for ‘Numerical Python’.
• It is the core library for scientific computing, which contains a
powerful n-dimensional array object.
Monday, September 18, 2023 Indira College of Engineering Management, Pune
Why NumPy?
• We use python NumPy array instead of a list because of the below
three reasons:
1. Less Memory
2. Fast
3. Convenient
Monday, September 18, 2023 Indira College of Engineering Management, Pune
Where is NumPy used?
• Python NumPy arrays provide tools for integrating C, C++, etc.
• It is also useful in Mathematics,Statistics, linear algebra, random number capability, load data from file,
miscellaneous etc. NumPy array can also be used as an efficient multi-dimensional container for generic data.
• Basics:
ndim,
shape,
size,
accessing/changing specific elements,
row,
col,
reshape,
stacking
• Mathematics;Addition,subtraction,mult,div,sin,cos,**
• Linear Algebra: Matmul,identity matrix,determinant,eigen values…
• Statistics:mean,max,min,median,standard deviation
• Random number generation
• Miss:load data fromfile,astype,advance indexing
Monday, September 18, 2023 Indira College of Engineering Management, Pune
NumPy Operations
• ndim
• itemsize
• dtype
• reshape
• shape
• size
• slice
• linespace
• max/min
• square root and standard deviation
• Addition, Subtraction, Multiplication, Division,transpose
• Vertical and Horizontal Stacking
• union,intersection,set difference
• save and load
• Special function: sin, cos, tan, log
Monday, September 18, 2023 Indira College of Engineering Management, Pune
#Data Analysis of Cab ride of Newyork city toand from the airport
import numpy as np
t=np.genfromtxt("taxi.csv",delimiter=',',skip_header=True)
t=t.astype('int32')
print(t)
#Prints Diminesions
print(t.ndim)
#Prints number of rows in dataset
print("Rows are ",t.shape[0])
#Prints number of columns in dataset
print("Columns are ",t.shape[1])
#print Size of 2d array
print("Size is ",t.size)
#Mean speed of all the rides
#speed =dist/time
speed=t[:,7]/(t[:,8]/3600)
mspeed=speed.mean()
print(mspeed)
#Number of rides taken in Feb
rides=t[t[:,1]==2,1]
print(rides.shape[0])
#Number of rides where tip was more then $50
print(t[t[:,-3]>50,-3].shape[0])
Monday, September 18, 2023 Indira College of Engineering Management, Pune