NumPy Assignment– 4

Statistical & Mathematical Functions

Basic Questions

  1. Create a 1D array of numbers 1–10. Calculate and print its sum using np.sum().
  2. Generate a 1D array [10,20,30,40,50]. Compute and print its mean using np.mean().
  3. Create an array [1,2,3,4,5,6]. Find the median using np.median().
  4. Generate a 1D array of numbers [1,2,3,4,5]. Compute its standard deviation with np.std().
  5. Compute variance of [2,4,6,8,10] using np.var().
  6. Find the minimum value of [5,10,2,8,15] using np.min().
  7. Find the maximum value of [5,10,2,8,15] using np.max().
  8. Find the range (peak-to-peak) of [10,50,30,70,90] using np.ptp().
  9. Use np.argmin() to get the index of the smallest element in [8,3,7,1,9].
  10. Use np.argmax() to get the index of the largest element in [8,3,7,1,9].
  11. Compute cumulative sum of [1,2,3,4,5] using np.cumsum().
  12. Compute cumulative product of [1,2,3,4] using np.cumprod().
  13. Create an array of angles [0, np.pi/2, np.pi]. Apply np.sin() on it.
  14. Use np.cos() on [0, np.pi/2, np.pi].
  15. Use np.tan() on [0, np.pi/4, np.pi/2].
  16. Apply np.round() on [1.2, 2.5, 3.7, 4.8].
  17. Apply np.floor() on [1.2, 2.5, 3.7, 4.8].
  18. Apply np.ceil() on [1.2, 2.5, 3.7, 4.8].
  19. Generate a 2D array of shape (2,3). Compute the sum of all elements.
  20. Create a 2D array (3×3). Compute mean along axis=0 and axis=1.

Intermediate Questions

  1. Create an array of 20 random integers between 1 and 100. Compute sum, mean, median, std, and var.
  2. Generate a 2D 4×4 array of numbers 1–16. Find the min, max, and range (np.ptp()).
  3. From the same 4×4 array, find the index of the minimum and maximum elements using np.argmin() and np.argmax().
  4. Generate an array [1,2,3,4,5,6,7,8,9,10]. Print cumulative sum and cumulative product.
  5. Create an array of 10 random floats between 0 and 10. Apply np.round(), np.floor(), and np.ceil() on it.
  6. Create an array of angles from 0 to 2π (10 values). Apply np.sin(), np.cos(), and np.tan().
  7. Generate a 2D 5×5 matrix of random integers 1–50. Compute sum along rows and columns.
  8. Compute mean of the 5×5 matrix along axis=0 and axis=1.
  9. Compute median of the 5×5 matrix along both axes.
  10. Generate an array of 15 random integers. Normalize it (subtract mean and divide by std).
  11. Create an array of 10 random integers 1–100. Replace the max value with -1 using np.argmax().
  12. Create an array of 10 random integers 1–100. Replace the min value with -1 using np.argmin().
  13. Create a 3×3 array with values from 1 to 9. Find mean of diagonal elements using slicing.
  14. Generate an array of 10 numbers between 0 and 1. Apply log transform using np.log().
  15. Apply exponential transform (np.exp()) on the same array.
  16. Compute variance and std of a 2D array (4×4) both globally and along axis=0.
  17. Create a 1D array [2,4,6,8,10]. Compute (x – mean)/std for each element (z-score).
  18. Generate a 2D 6×6 array of random floats between 0 and 10. Apply np.round(…,2) to keep two decimal places.
  19. Demonstrate the difference between np.round(), np.floor(), and np.ceil() on [1.1, 1.9, 2.5, 3.5].
  20. Create a matrix of shape (3,4). Find cumulative sum along axis=1 and cumulative product along axis=0.

Advanced Questions

  1. Generate a 100-element random array from normal distribution. Compute mean, median, variance, std, min, max, and range.
  2. 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().
  3. 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().
  4. Generate a 3D array (3x3x3). Find min, max, and mean along different axes.
  5. Build a small trigonometric table: angles [0, 30, 45, 60, 90] degrees converted to radians. Compute sin, cos, and tan.
  6. Create a 20-element random array. Apply rounding functions (round, floor, ceil) and compare results in a table format.
  7. Generate a 5×5 matrix of random floats. Normalize each column separately using (x – mean)/std.
  8. Simulate rolling a dice 1000 times using np.random.randint(1,7,1000). Compute mean, variance, and std of results.
  9. Create a 15-element random integer array. Replace all local maxima (greater than neighbors) with -1.
  10. Create a 3×3 matrix with random integers. Print row index of the maximum element in each column using np.argmax(…,axis=0).