Q1: Array Creation & Basic Operations
Create a 4x4 NumPy array with values from 1 to 16.
• Reshape it into a 2D matrix.
• Find the sum of each row and sum of each column.
Q2: Indexing & Slicing
Given the array:
arr = np.array([10, 20, 30, 40, 50, 60, 70])
• Extract elements from index 2 to 5.
• Replace all even numbers with -1.
Q3: Boolean Masking
Given the array:
arr = np.array([15, 23, 8, 42, 4, 16, 9])
• Find all numbers greater than 10 and divisible by 2.
• Replace those numbers with 0.
Q4: Broadcasting & Mathematical Operations
Create a 1D array a = np.array([1, 2, 3]) and a 2D array
b = np.array([[10], [20], [30]])
• Use broadcasting to add them together.
• Compute the element-wise multiplication without using a loop.
Q5: Statistics & Random Numbers
• Generate a random 5x5 matrix with values between 0 and 1.
• Find the mean, median, variance, and standard deviation.
• Normalize the matrix (scale values between 0 and 1).
Normalize (0 to 1 scaling) use this equation
norm = (matrix - np.min(matrix)) / (np.max(matrix) - np.min(matrix))