Python lab 7
Python lab 7
Page 1 of 11
Course Material
Semester &
Class & Section I M.Sc(CS) ‘A’ I Semester, 2024-25
Academic Year
7. Numpy Libraries
a. Matrix Operation Add, Subtract and Multiply
b. Binary Operations
1. numpy.bitwise_and() :
# Python program explaining
# bitwise_and() function
2. numpy.bitwise_or()
# Python program explaining
# bitwise_or() function
3. numpy.bitwise_xor()
# Python program explaining
# bitwise_xor() function
c. Mathematical Functions
1. Trigonometric Functions
2. Arithmetic Functions
3. Rounding Functions
1. Trigonometric Functions
2. Arithmetic Functions
Effective Date 21.08.2024 Page No. Page 7 of 11
3. Rounding Functions
a) round( ) function
import numpy as np
numbers = np.array([1.23456, 2.34567, 3.45678, 4.56789])
# round the array to two decimal places
rounded_array = np.round(numbers, 2)
print(rounded_array)
ceil( ) function
import numpy as np
d. String Operations
1. numpy.lower()
# Python program explaining
# numpy.lower() function
import numpy as np
# converting to lowercase
print(np.char.lower(['GEEKS', 'FOR']))
# converting to lowercase
print(np.char.lower('GEEKS'))
2. numpy.split()
# Python program explaining
# numpy.split() function
import numpy as np
# splitting a string
print(np.char.split('geeks for geeks'))
# splitting a string
print(np.char.split('g e e k s, f o r, g e e k s', sep = ':'))
3. numpy.join()
# Python program explaining
# numpy.join() function
import numpy as np
# splitting a string
print(np.char.join('-', 'geeks'))
# splitting a string
print(np.char.join(['-', ':'], ['geeks', 'for']))
Page 10 of
Effective Date 21.08.2024 Page No.
11
4. numpy.count()
# Python program explaining
# numpy.count() function
import numpy as np
# counting a substring
print(np.char.count(a,'geek'))
# counting a substring
print(np.char.count(a, 'fo'))
5. numpy.isnumeric() :
# Python program explaining
# numpy.isnumeric() function
import numpy as np
# counting a substring
print(np.char.isnumeric('geeks'))
# counting a substring
print(np.char.isnumeric('12geeks'))
6. numpy.equal():
# Python program explaining
# numpy.equal() function
import numpy as np
print(a)
7. numpy.not_equal ( )
import numpy as np
print(a)