0% found this document useful (0 votes)
23 views13 pages

Numpy

The document outlines various tasks related to data analysis using NumPy, including weather data analysis, sales tracking, image simulation, student attendance analysis, and budget management. It also includes a set of multiple-choice questions to test intermediate-level knowledge of NumPy functionalities. Each section specifies tasks that involve calculations, aggregations, and data manipulations using 1D and 2D arrays.

Uploaded by

Nitin Ojha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views13 pages

Numpy

The document outlines various tasks related to data analysis using NumPy, including weather data analysis, sales tracking, image simulation, student attendance analysis, and budget management. It also includes a set of multiple-choice questions to test intermediate-level knowledge of NumPy functionalities. Each section specifies tasks that involve calculations, aggregations, and data manipulations using 1D and 2D arrays.

Uploaded by

Nitin Ojha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

✅ 1.

Weather Data Analysis


📌 Concept: 2D Arrays, Indexing, Aggregation
# Daily temperature data (°C) for 7 days, recorded 3 times a day
temps = np.array([
[28, 30, 29],
[31, 32, 30],
[27, 28, 26],
[29, 30, 28],
[32, 34, 33],
[30, 29, 31],
[26, 27, 25]
])

Tasks:

●​ Calculate the average temperature per day.​

●​ Find the highest and lowest temperature recorded in the week.​

●​ Print temperature data for the weekend (Sat, Sun).​

●​ How many times was the temperature above 30°C?


✅ 2. Sales Tracker
📌 Concept: Array Operations, Axis-wise Calculations
# Sales (in units) for 4 products over 5 days
sales = np.array([
[10, 12, 11, 15, 14],
[7, 9, 8, 10, 12],
[14, 15, 13, 17, 19],
[5, 6, 7, 5, 4]
])

Tasks:

●​ Calculate total sales per product.​

●​ Calculate average sales per day.​

●​ Identify the day with the highest total sales.​

●​ Apply a 10% increase to all sales.​


✅ 3. Grayscale Image Simulation
📌 Concept: 2D Arrays, Image Logic
# 5x5 image pixels (0 to 255 for brightness)
image = np.array([
[100, 120, 130, 110, 90],
[95, 105, 115, 125, 85],
[80, 90, 100, 110, 70],
[60, 75, 85, 95, 65],
[50, 55, 60, 70, 45]
])

Tasks:

●​ Increase brightness by 10.​

●​ Set all pixels below 80 to 0 (simulate thresholding).​

●​ Count how many pixels are above 100.​

●​ Invert the image: 255 - pixel​


✅ 4. Student Attendance Analyzer
📌 Concept: Boolean Indexing, Axis Ops
# 1 = Present, 0 = Absent for 6 students over 5 days
attendance = np.array([
[1, 1, 0, 1, 1],
[1, 0, 0, 1, 1],
[1, 1, 1, 1, 1],
[0, 0, 1, 1, 0],
[1, 1, 1, 0, 1],
[1, 1, 0, 1, 1]
])

Tasks:

●​ Total attendance for each student.​

●​ Day-wise average attendance.​

●​ Which student has perfect attendance?​

●​ Which day had the lowest attendance?​


✅ 5. Budget Manager
📌 Concept: 1D & 2D Arrays, Arithmetic
# Monthly expenses (in ₹) for 3 categories over 4 months
expenses = np.array([
[12000, 15000, 10000, 11000], # Food
[8000, 8500, 7900, 8200], # Rent
[5000, 5200, 5100, 4800] # Transport
])

Tasks:

●​ Calculate total expense per month.​

●​ Find which category costs the most.​

●​ Average monthly expenditure.​

●​ Apply a 5% increase in rent and recalculate totals.


📘 NumPy Intermediate-Level MCQ Test (25 Questions)
Q1. What does np.full((2, 3), 7) return?​
A. A 2x3 array filled with 0s​
B. A 2x3 array filled with 7s​
C. A 3x2 array filled with 7s​
D. A 2x3 identity matrix

Q2. Which method returns a copy of an array with a different shape but does not modify the
original?​
A. reshape()​
B. resize()​
C. split()​
D. slice()

Q3. What is the default data type of np.ones((2,2))?​


A. int​
B. float64​
C. bool​
D. complex

Q4. What does np.diag([1, 2, 3]) do?​


A. Returns diagonal elements of a matrix​
B. Creates a diagonal matrix with the given values​
C. Adds values to diagonal​
D. Flattens the array

Q5. What is the output shape of np.dot(np.ones((2,3)), np.ones((3,1)))?​


A. (2,1)​
B. (3,2)​
C. (2,3)​
D. (3,3)
Q6. Which method is used to join arrays along a new axis?​
A. np.append()​
B. np.hstack()​
C. np.concatenate()​
D. np.stack()

Q7. What does np.argmax(arr) return?​


A. Maximum value in array​
B. Index of first maximum value​
C. Index of last maximum value​
D. Mean of array

Q8. What is returned by arr.T for a 2D NumPy array?​


A. Sum of rows​
B. Transpose of the array​
C. Dot product​
D. Reshaped array

Q9. What will np.clip(arr, 2, 5) do?​


A. Set all values below 2 and above 5 to 0​
B. Replace all values with 2 and 5​
C. Limit all values to the range [2,5]​
D. Remove elements not in range

Q10. What is np.where(arr > 0) used for?​


A. Replace 0s with 1s​
B. Find indexes where condition is True​
C. Sum positive numbers​
D. Mask negative values

Q11. What does np.cumsum([1,2,3,4]) return?​


A. [1, 3, 6, 10]​
B. [1, 2, 3, 4]​
C. 10​
D. [10, 9, 7, 4]

Q12. What does np.allclose([1.0, 2.0], [1.0, 2.00000001]) check?​


A. Whether values are exactly equal​
B. Whether arrays are same length​
C. Whether values are approximately equal​
D. Checks for NaNs

Q13. What is the result of broadcasting [1, 2, 3] with [[1], [2]]?​


A. Error​
B. (2, 3) array​
C. (3, 2) array​
D. (3, 3) array

Q14. Which function generates evenly spaced numbers on a log scale?​


A. np.linspace()​
B. np.log()​
C. np.logspace()​
D. np.geomspace()

Q15. What does arr.shape return?​


A. Size of each element​
B. Type of array​
C. Dimensions of array​
D. Total elements

Q16. What does np.isfinite(np.array([1, np.inf])) return?​


A. [True, True]​
B. [True, False]​
C. [False, False]​
D. Error
Q17. What is the output type of np.sum(arr, axis=0)?​
A. Scalar​
B. List​
C. Array​
D. Float

Q18. np.tile([1,2], (2,3)) creates:​


A. A 2x3 array of 1s and 2s​
B. A repeated pattern of [1,2]​
C. A matrix of zeros​
D. A flattened array

Q19. Which one creates a boolean mask for values greater than 3 in arr?​
A. arr > 3​
B. np.greater(3, arr)​
C. arr[arr > 3]​
D. np.select(arr > 3)

Q20. What does np.random.seed(42) do?​


A. Randomizes the seed​
B. Sets global seed for reproducibility​
C. Resets all arrays​
D. Disables randomness

Q21. What will np.unique([1,2,2,3,3,3]) return?​


A. [3,2,1]​
B. [1,2,3]​
C. [1,2,2,3,3,3]​
D. [1,1,2,2,3,3]

Q22. What is np.nanmean([1, 2, np.nan, 4])?​


A. 2.5​
B. nan​
C. 3​
D. Error

Q23. What will np.flip(np.array([[1,2], [3,4]])) do?​


A. Flip horizontally​
B. Flip vertically​
C. Flatten​
D. Flip entire array

Q24. Which function returns a flattened version of the array?​


A. flatten()​
B. reshape(-1)​
C. ravel()​
D. All of the above

Q25. Which of the following removes single-dimensional entries from the shape of an array?​
A. reshape()​
B. squeeze()​
C. flatten()​
D. expand_dims()
1. Weather Data Analysis​
You have daily temperature data for 30 days stored in a 1D NumPy array.​
Tasks:

●​ Calculate mean, max, min temperature.​

●​ Find number of days with temperature > average.​

●​ Smooth the data using a 3-day moving average.​

2. Game Score Simulation​


Simulate scores of 4 players in 10 rounds (random integers 0-100).​
Tasks:

●​ Generate the data using NumPy.​

●​ Calculate the cumulative score of each player.​

●​ Identify the round when each player had their highest score.​

3. Stock Price Analyzer​


You have closing prices of a stock for 15 days.​
Tasks:

●​ Calculate daily percentage change.​

●​ Identify highest gain and highest drop days.​

●​ Calculate 5-day rolling average.​


4. Hospital Bed Occupancy Tracker​
You’re tracking daily bed occupancy (number) across 5 departments over 7 days.​
Tasks:

●​ Create a 2D array (5x7).​

●​ Find the department with highest average occupancy.​

●​ Calculate total occupancy for each day.​

5. Electricity Consumption Model​


Given hourly electricity usage data for 2 days (48 values):​
Tasks:

●​ Reshape into a (2, 24) array.​

●​ Compute total consumption per day.​

●​ Highlight hours with usage > 1.5× daily average.​

6. Sports Tournament Matrix​


Given a matrix where arr[i][j] = 1 if team i defeated team j, 0 otherwise.​
Tasks:

●​ Identify unbeaten teams.​

●​ Count how many matches each team won.​

●​ Find the team that lost the most.​

7. COVID Cases Simulation​


You are given NumPy arrays of daily new COVID cases across 3 states for 30 days.​
Tasks:

●​ Plot daily total cases across all states.​


●​ Find peak day for each state.​

●​ Calculate 7-day moving average for each state.​

You might also like