0% found this document useful (0 votes)
8 views3 pages

NumPy Assignments for CSE Workshop

Uploaded by

forotheruse2006
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)
8 views3 pages

NumPy Assignments for CSE Workshop

Uploaded by

forotheruse2006
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

Assignment-8 The “numpy” (Numeric

Python) Package
Subject: Computer Science Workshop - 1 (CSE 2141)
Session: Sep 2025 to Jan 2026
Branch: Computer Science and Engineering (CSE)
Section: All
Course Outcome: CO5, CO6
Program Outcomes: PO1, PO2, PO3, and PO5
Learning Levels: Remembering (L1), Understanding (L2), Application (L3), Analysis (L4)

Q no. Questions Learning


Levels
Q1. Initialize two integer 1-D vectors v1 randomly using numpy. Calculate and print the L1, L2
following-
a. Find the maxi and mini value
b. Find the number of elements present in between max and min
Note: Consider the duplicates in the array

Q2. Initialize two integer 2-D vectors v1 and v2 randomly using numpy. Calculate and L1, L2
print the following-
a. Length of the vectors.
b. Normalized (i.e., unit length) v1Norm and v2Norm.
c. Angle between the vectors in degree and radian.

Q3. Use [Link] package to generate a 2D array of size 1000 × 1000 filled with L2, L3
random floating-point numbers in the range [0, 1). Measure and display the execution
time required for this operation. Next, generate an equivalent 2D array of size 1000 ×
1000 using Python’s built-in [Link]() function with nested for loops.
Measure the execution time for this approach as well. Finally, compare the two
execution times and clearly print which method (NumPy or Python nested loops) is
faster.

Q4. A weather monitoring system records daily temperatures (in °C) for a city over 14 L2, L3
days. Perform following task using the concept “Boolean masking in Numpy”:

 Identify heat-wave days where temperature is ≥ 35°C

 Count the number of heat-wave days

 Replace temperatures below 30°C with the value 30

 Extract only comfortable days (30°C to 34°C inclusive)

 Increase all heat-wave day temperatures by 2°C (data correction)


Q5. A hospital stores fasting blood sugar levels (mg/dL) of multiple patients in a NumPy L2, L4
array. You are asked to do the following task:

1. Create boolean masks using NumPy to identify patients belonging to different


risk categories.
2. Classify each patient into one of the following medical conditions:

1. Normal → blood sugar < 100


2. Pre-Diabetic → blood sugar between 100 and 139
(inclusive)
3. Diabetic → blood sugar ≥ 140

3. Store the classification result in a separate NumPy array of the same size.

Do not use loops (for / while). Use boolean masking only.


Q6. Design a method in python to generate a NumPy array of 1000 observations and L3, L4
calculate its mean and standard deviation.

Design another method to analyze the distribution by counting the number of values
that lie within one, two, and three standard deviation intervals around the mean,
which will be stored in a dictionary. Print the dictionary outside of the metod.

Q7. Develop a matrix-based guessing game in which the matrix size is specified by the L2, L3
user. For each row of the matrix, the system randomly chooses a hidden number. The
user repeatedly inputs guesses for each row until the correct number is guessed.
Determine and report the number of trials taken for each row to achieve a correct
guess.
Q8. Design a method to generate a 4 × 5 matrix such that the elements of each row are L2, L4
randomly generated within a specific range defined by the row index.
For the row at index i (0-based indexing), the values should be generated in the range
(i + 1) to (i + 9).

After constructing the matrix:

1. Compute the mean and standard deviation row-wise and column-wise.


2. Compare the row-wise and column-wise results separately for mean and
standard deviation.
3. Determine which dimension (row-wise or column-wise) has the larger
overall value for mean and for standard deviation.
4. Return the final outcome as a dictionary with the keys:
i) "mean" → indicating whether row-wise or column-wise mean is
dominant
ii) "std" → indicating whether row-wise or column-wise standard
deviation is dominant
Q9. Using NumPy, generate a three-dimensional array and normalize the data L3, L4
independently along each dimension.
Return the resulting array after applying the normalization.

-END-

You might also like