Day-3 Assignment: NumPy
Basics
This assignment will help you practice Python basics with NumPy.
Topics included: input, int, str, float, if-else, operators, [Link](), [Link](), [Link](), .size, .shape, .ndim,
.dtype, .astype(), [Link](), [Link](), [Link](), [Link](), [Link](), [Link](), [Link](), [Link](), [Link](),
[Link]()
Section A – Array Creation & Basics
1. Take 3 numbers from the user and store them in a NumPy array. Print the
array.
Hint: Use [Link]() with input() .
2. Create a 1D array of 5 integers using NumPy. Print its size.
Hint: Use .size .
3. Create a 2×3 array filled with zeros.
Hint: Use [Link]((rows, cols)) .
4. Create a 3×2 array filled with ones.
Day-3 Assignment: NumPy Basics 1
Hint: Use [Link]((rows, cols)) .
5. Take 2 integers from the user and create an array. Print its shape.
Hint: Use .shape .
Section B – Array Properties
1. Create a NumPy array [1, 2, 3, 4] . Print its number of dimensions.
Hint: Use .ndim .
2. Take 4 numbers as input, create an array, and print its data type.
Hint: Use .dtype .
3. Convert an integer array into float type.
Hint: Use .astype(float) .
Section C – Arithmetic Operations
1. Create two arrays [1, 2, 3] and [4, 5, 6] . Add them element-wise.
Hint: Use + or [Link]() .
2. Multiply two arrays [2, 4, 6] and [1, 3, 5] .
Hint: Use * or [Link]() .
3. Divide [10, 20, 30] by [2, 5, 10] .
Hint: Use / or [Link]() .
4. Subtract [5, 10, 15] from [20, 30, 40] .
Hint: Use - or [Link]() .
5. Take 2 numbers from the user, put them in an array, and print the square of
each.
Hint: Use ** 2 .
Section D – If-Else with Arrays
1. Take 3 marks from user, find average, and check if student passed (≥40).
Day-3 Assignment: NumPy Basics 2
Hint: Use [Link]() + if-else.
2. Take 3 numbers, find maximum, and check if it is greater than 100.
Hint: Use [Link]() + if-else.
3. Take 5 numbers as input, check if the array size is greater than 4.
Hint: Use .size + if-else.
4. Compare averages of two arrays given by user and print which is higher.
Hint: Use [Link]() + if-else.
5. Create an array of 3 numbers. If the minimum value is less than 0, print
“Negative number exists”.
Hint: Use [Link]() + if-else.
Section E – Statistical Functions
1. Find the average of [10, 20, 30, 40, 50] .
Hint: Use [Link]() .
2. Find the median of [7, 2, 9, 1, 6] .
Hint: Use [Link]() .
3. Find the standard deviation of [10, 12, 23, 23, 16, 23, 21, 16] .
Hint: Use [Link]() .
4. Find the variance of [2, 4, 6, 8, 10] .
Hint: Use [Link]() .
5. Find the maximum salary from [25000, 40000, 35000, 28000] .
Hint: Use [Link]() .
6. Find the minimum temperature from [32, 28, 30, 27, 29] .
Hint: Use [Link]() .
Section F – Small Applications
Day-3 Assignment: NumPy Basics 3
1. Take 3 exam scores from the user. If the average is more than 90, print “Grade
A”. Else print “Grade B”.
Hint: Use [Link]() + if-else.
2. Ask the user for 2 ages. Find which is larger using NumPy.
Hint: Use [Link]() .
3. Create an array of 3 numbers. If all numbers are even, print “Even array”.
Otherwise, print “Mixed”.
Hint: Use %2 with if-else.
4. Ask the user to enter 2 salaries. Print both and show their difference.
Hint: Use [Link]() .
5. Create an array of [3, 6, 9] . Multiply every element by 10.
Hint: Use * operator.
6. Take 3 floating-point numbers from the user. Convert them into integers using
NumPy.
Hint: Use .astype(int) .
1. Array Creation
import numpy as np
# From list
arr = [Link]([1, 2, 3])
# Zeros & Ones
[Link]((rows, cols)) # [Link]((2,3)) → 2x3 all zeros
[Link]((rows, cols)) # [Link]((3,2)) → 3x2 all ones
2. Array Properties
Day-3 Assignment: NumPy Basics 4
[Link] # Dimensions (rows, cols)
[Link] # Number of dimensions (1D, 2D…)
[Link] # Total elements
[Link] # Data type (int, float, etc.)
[Link](float) # Convert to float
[Link](int) # Convert to int
3. Arithmetic Operations
a = [Link]([1, 2, 3])
b = [Link]([4, 5, 6])
a+b # element-wise addition
a-b # subtraction
a*b # multiplication
a/b # division
a ** 2 # power (square)
[Link](a, b) # addition
[Link](a, b) # subtraction
[Link](a, b) # multiplication
[Link](a, b) # division
4. Statistical Functions
arr = [Link]([10, 20, 30, 40])
[Link](arr) # Average
[Link](arr) # Middle value
[Link](arr) # Standard deviation
Day-3 Assignment: NumPy Basics 5
[Link](arr) # Variance
[Link](arr) # Smallest value
[Link](arr) # Largest value
5. If-Else with NumPy
arr = [Link]([10, 20, 30])
avg = [Link](arr)
if avg > 50:
print("Average is greater than 50")
else:
print("Average is less or equal to 50")
if [Link](arr) > 100:
print("Large value found")
Day-3 Assignment: NumPy Basics 6