Page 190 - Robotics and AI class 10
P. 190
// import numpy as np [ 5 5 10 8]
(floor division) marks1 = np.array([10,20,30,40]) 2 marks divided using
marks2=np.array([2,4,3,5]) floor division: [ 5 10 15
20]
print(marks1//marks2)
print("2 marks divided using floor
division:",marks1//2)
% import numpy as np [0 0 0 0]
(Remainder of marks1 = np.array([10,20,30,40]) remainder of division:
division) marks2=np.array([1,2,3,4]) [1 2 0 1]
print(marks1%marks2)
print("remainder of
division:",marks1%3)
Some of the basic mathematical operations can also be done by using built-in functions like:
1. Addition: np.add()
2. Subtraction: np.subtract()
3. Multiplication: np.multiply()
4. Division: np.divide()
5. Remainder: np.remainder()
Some important attributes and functions of NumPy Array:
Type Function Example Output
Type of an object type(ARR) import numpy as np <class 'numpy.
i.e. array ARR = np.array([1,2,3,4]) ndarray'>
print(type(ARR))
gives the ARR.ndim import numpy as np 2
dimensions of an ARR = np.array([[1,2,3,4],
array as an integer [3,4,5,6]])
value. Arrays can print(ARR.ndim)
be 1-D, 2-D or n-D.
Shape of an array ARR.shape import numpy as np (2, 4)
i.e. length of the ARR =
array of each np.array([[1,2,3,4],
dimension [3,4,5,6]])
print(ARR.shape)
Size of an array ARR.size import numpy as np 8
i.e. counts the ARR =
total number of np.array([[1,2,3,4],
elements [3,4,5,6]])
print(ARR.size)
188 Touchpad Robotics & Artificial Intelligence-X

