Numy Session 2 Code

Numy Session 2 Code For Video Click Fahad Hussain CS


import numpy as np

a = np.array([[1,2],

             [3,4]])

b = np.array([[7,8],

             [9,5]])

# vertical stacking 

print(np.vstack((a, b)))

# horizontal stacking 

print(np.hstack((a, b)))

# stacking columns 

c = [10,5] 

print(np.column_stack((a, c)))

# concatenation method 

print(np.concatenate((a, b), 1))


a = np.array([[1,2,3,4,5,7],

              [8,7,6,5,9,4]])

# horizontal splitting 

print(np.hsplit(a,2))

# vertical splitting 

print(np.vsplit(a,2))


c = np.array([1,23,4,54,5,6,7,7])

# horizontal splitting 

print(np.split(c,2))


###### Boradcasting

a = np.array([1.0,2.0,3.0])


b = 2.0

print(a * b)


c = [2.0,3.0,4.0]

print(a * c)


a = np.array([1.0,2.0,3.0,4.0])

b = np.array([0.0,1.0,2.0])

print(a[:, np.newaxis] + b)

a = np.array([[0.0,0.0,0.0],[10.0,10.0,10.0],[20.0,20.0,20.0],[30.0,30.0,30.0]]) 

b = np.array([1.0,2.0,3.0])  

   


print(a) 

print(b) 

print(a + b)


####DateTime Working 

# creating a date 

today = np.datetime64('2020-12-15') 

print("Date is:", today) 

print("Year is:", np.datetime64(today, 'Y')) 


# creating array of dates in a month 

dates = np.arange('2017-02', '2017-03', dtype='datetime64[D]') 

print("\nDates of February, 2017:\n", dates) 

print("Today is February:", today in dates) 


# arithmetic operation on dates 

dur = np.datetime64('2017-05-22') - np.datetime64('2016-05-22') 

print("\nNo. of days:", dur) 

print("No. of weeks:", np.timedelta64(dur, 'W')) 


# sorting dates 

a = np.array(['2017-02-12', '2016-10-13', '2019-05-22'], dtype='datetime64') 

print("\nDates in sorted order:", np.sort(a))


No comments:

Post a Comment

Fell free to write your query in comment. Your Comments will be fully encouraged.