NumPy Assignment– 4
Statistical & Mathematical Functions
Basic Questions
- Create a 1D array of numbers 1–10. Calculate and print its sum using np.sum().
- Generate a 1D array [10,20,30,40,50]. Compute and print its mean using np.mean().
- Create an array [1,2,3,4,5,6]. Find the median using np.median().
- Generate a 1D array of numbers [1,2,3,4,5]. Compute its standard deviation with np.std().
- Compute variance of [2,4,6,8,10] using np.var().
- Find the minimum value of [5,10,2,8,15] using np.min().
- Find the maximum value of [5,10,2,8,15] using np.max().
- Find the range (peak-to-peak) of [10,50,30,70,90] using np.ptp().
- Use np.argmin() to get the index of the smallest element in [8,3,7,1,9].
- Use np.argmax() to get the index of the largest element in [8,3,7,1,9].
- Compute cumulative sum of [1,2,3,4,5] using np.cumsum().
- Compute cumulative product of [1,2,3,4] using np.cumprod().
- Create an array of angles [0, np.pi/2, np.pi]. Apply np.sin() on it.
- Use np.cos() on [0, np.pi/2, np.pi].
- Use np.tan() on [0, np.pi/4, np.pi/2].
- Apply np.round() on [1.2, 2.5, 3.7, 4.8].
- Apply np.floor() on [1.2, 2.5, 3.7, 4.8].
- Apply np.ceil() on [1.2, 2.5, 3.7, 4.8].
- Generate a 2D array of shape (2,3). Compute the sum of all elements.
- Create a 2D array (3×3). Compute mean along axis=0 and axis=1.
Intermediate Questions
- Create an array of 20 random integers between 1 and 100. Compute sum, mean, median, std, and var.
- Generate a 2D 4×4 array of numbers 1–16. Find the min, max, and range (np.ptp()).
- From the same 4×4 array, find the index of the minimum and maximum elements using np.argmin() and np.argmax().
- Generate an array [1,2,3,4,5,6,7,8,9,10]. Print cumulative sum and cumulative product.
- Create an array of 10 random floats between 0 and 10. Apply np.round(), np.floor(), and np.ceil() on it.
- Create an array of angles from 0 to 2π (10 values). Apply np.sin(), np.cos(), and np.tan().
- Generate a 2D 5×5 matrix of random integers 1–50. Compute sum along rows and columns.
- Compute mean of the 5×5 matrix along axis=0 and axis=1.
- Compute median of the 5×5 matrix along both axes.
- Generate an array of 15 random integers. Normalize it (subtract mean and divide by std).
- Create an array of 10 random integers 1–100. Replace the max value with -1 using np.argmax().
- Create an array of 10 random integers 1–100. Replace the min value with -1 using np.argmin().
- Create a 3×3 array with values from 1 to 9. Find mean of diagonal elements using slicing.
- Generate an array of 10 numbers between 0 and 1. Apply log transform using np.log().
- Apply exponential transform (np.exp()) on the same array.
- Compute variance and std of a 2D array (4×4) both globally and along axis=0.
- Create a 1D array [2,4,6,8,10]. Compute (x – mean)/std for each element (z-score).
- Generate a 2D 6×6 array of random floats between 0 and 10. Apply np.round(…,2) to keep two decimal places.
- Demonstrate the difference between np.round(), np.floor(), and np.ceil() on [1.1, 1.9, 2.5, 3.5].
- Create a matrix of shape (3,4). Find cumulative sum along axis=1 and cumulative product along axis=0.
Advanced Questions
- Generate a 100-element random array from normal distribution. Compute mean, median, variance, std, min, max, and range.
- Create a 10×10 matrix of random integers 1–100. Find the index of the maximum element using np.argmax() and print its row and column index using np.unravel_index().
- Create a 1D array of size 50 with values 1–50. Compute cumulative sum and cumulative product. Compare final values with np.sum() and np.prod().
- Generate a 3D array (3x3x3). Find min, max, and mean along different axes.
- Build a small trigonometric table: angles [0, 30, 45, 60, 90] degrees converted to radians. Compute sin, cos, and tan.
- Create a 20-element random array. Apply rounding functions (round, floor, ceil) and compare results in a table format.
- Generate a 5×5 matrix of random floats. Normalize each column separately using (x – mean)/std.
- Simulate rolling a dice 1000 times using np.random.randint(1,7,1000). Compute mean, variance, and std of results.
- Create a 15-element random integer array. Replace all local maxima (greater than neighbors) with -1.
- Create a 3×3 matrix with random integers. Print row index of the maximum element in each column using np.argmax(…,axis=0).
