Professional Documents
Culture Documents
PYTHON
FOR
MACHINE LEARNING
Course Code –
INT 215
Continuous Assessment - II
Page 1
IMPORTANT GUIDELINES:
4. For every question attempted, write the question no. , complete question
and the solution of the question in a jupyter notebook (.ipynb file).
5. After attempting the questions, convert the .ipynb file into a single pdf
format document (can be done with many free online available converters).
6. This PDF file should be uploaded onto the UMS interface on or before the
last date of the submission.
7. Refrain from indulging into plagiarism as copy cases will be marked zero.
Page 2
PYTHON FOR MACHINE LEARNING (INT-215)
CA-1
Set-1
1. You are given a list of numbers. Using NumPy, create an array of these numbers and calculate the
mean, median and standard deviation of the array.
2. You are given a 2D array of numbers. Using slicing and indexing operations, extract the values
from the second row and third column.
3. You have two arrays of equal length. Using NumPy, calculate the dot product of these arrays.
4. You have an array of shape (3, 4). Using NumPy, reshape it into an array of shape (2, 6).
5. You have two arrays of shape (2, 3) and (2, 4). Using NumPy, stack them horizontally and
vertically respectively.
6. You have an array of shape (4, 4). Using NumPy, split it into four equal parts.
7. You are given an array of numbers. Using NumPy, calculate the exponential of each element in
the array.
8. You have two arrays of equal length. Using NumPy, perform element-wise addition, subtraction,
multiplication and division on these arrays.
9. You have two arrays of shape (2, 2). Using NumPy, calculate the determinant of the product of
these two arrays.
10. You are given a list of names and their corresponding ages. Using Pandas, create a series of these
data.
11. You have a data frame containing the names, ages and grades of students. Using indexing and
selection operations, extract the grades of students who are above 18 years old.
12. You have two data frames containing the names and grades of students from two different
classes. Using Pandas, merge these data frames on the basis of the names of the students.
13. You have a data frame containing the names and ages of students from one class. Using Pandas,
append the data frame with the names and ages of students from another class.
Page 3
PYTHON FOR MACHINE LEARNING (INT-215)
CA-1
Set-2
1. You have an array of shape (5, 5). Using NumPy, create a new array that contains the diagonal
elements of the original array.
2. You have two arrays of shape (3, 3) and (3, 1). Using NumPy, perform matrix multiplication of
these arrays.
3. You are given an array of integers. Using NumPy, create a new array that contains only the
unique elements of the original array.
4. You have two arrays of shape (3, 3) and (3, 4). Using NumPy, concatenate these arrays along the
first axis.
5. You have an array of shape (2, 3, 4). Using NumPy, reshape it into an array of shape (2, 4, 3).
6. You have an array of shape (4, 4). Using NumPy, split it into two equal parts horizontally.
7. You are given an array of shape (3, 3). Using NumPy, calculate the inverse of this matrix.
8. You have two arrays of shape (2, 2) and (2, 2). Using NumPy, calculate the Kronecker product of
these arrays.
9. You are given an array of numbers. Using NumPy, calculate the cumulative sum and cumulative
product of this array.
10. You have a data frame containing the names, ages and salaries of employees. Using Pandas,
create a new data frame that contains only the names and salaries of employees who are older
than 30 years.
11. You have two data frames containing the names, ages and genders of students from two
different classes. Using Pandas, merge these data frames on the basis of the names of the
students and add a new column that contains the average age of the students from both classes.
12. You have a data frame containing the names and grades of students. Using Pandas, group the
data frame by grades and calculate the mean, median and standard deviation of the grades for
each group.
Page 4
PYTHON FOR MACHINE LEARNING (INT-215)
CA-1
Set-3
1. You have a 1D array of numbers. Using NumPy, create a new array that contains only the even
numbers from the original array.
2. You have two arrays of shape (2, 3) and (3, 2). Using NumPy, perform matrix multiplication of
these arrays.
3. You are given two arrays of equal length. Using NumPy, create a new array that contains the
maximum value of each pair of corresponding elements in the original arrays.
4. You have an array of shape (2, 3, 4). Using NumPy, split it into two equal parts along the second
axis.
5. You have two arrays of shape (3, 3) and (3, 3). Using NumPy, stack these arrays horizontally and
transpose the result.
6. You have an array of shape (3, 4). Using NumPy, reshape it into an array of shape (4, 3).
7. You are given an array of shape (4, 4). Using NumPy, calculate the eigenvalues and eigenvectors
of this matrix.
8. You have an array of shape (2, 2) and a scalar value. Using NumPy, calculate the exponential of
the product of the array and the scalar value.
9. You are given two arrays of shape (3, 3) and (3, 3). Using NumPy, perform element-wise
comparison of these arrays and create a new array that contains True where the corresponding
elements are equal and False otherwise.
10. You have a data frame containing the names and ages of students. Using Pandas, create a new
data frame that contains only the names and ages of students who are between 20 and 25 years
old.
11. You have a data frame containing the names and salaries of employees. Using Pandas, group the
data frame by department and calculate the total salary for each department.
12. You have a data frame containing the names, ages and grades of students. Using Pandas,
calculate the mean, median and standard deviation of the grades for each age group.
Page 5
PYTHON FOR MACHINE LEARNING (INT-215)
CA-1
Set-4
1. You have an array a of shape (3, 4) and an array b of shape (4, 5). Using NumPy, create a new
array c of shape (3, 5) that contains the dot product of a and b.
2. You have an array a of shape (5, 6) and an array b of shape (5, 6). Using NumPy, calculate the
Frobenius norm of the difference between a and b.
3. You have an array a of shape (4, 5) and a scalar value x. Using NumPy, create a new array b of
shape (4, 5) that contains the element-wise product of a and the sine of x.
4. You have an array a of shape (2, 3, 4). Using NumPy, split it into two arrays of shape (2, 3, 2) and
(2, 3, 2) along the second axis.
5. You have an array a of shape (3, 4) and an array b of shape (4, 5). Using NumPy, stack a and b
horizontally and reshape the result into an array of shape (3, 9).
6. You have an array a of shape (4, 3) and a scalar value x. Using NumPy, create a new array b of
shape (4, 3) that contains the element-wise product of a and the square of x.
7. You are given an array a of shape (3, 3). Using NumPy, calculate the determinant of a and verify
that the trace of a is equal to the sum of its eigenvalues.
8. You have an array a of shape (2, 2) and a scalar value x. Using NumPy, calculate the exponential
of a multiplied by x.
9. You are given two arrays a and b of shape (3, 3). Using NumPy, create a new array c of shape (3,
3) that contains the element-wise product of a and the sine of b.
10. You have a data frame containing the names, ages and grades of students. Using Pandas, create
a new data frame that contains only the names and ages of students who received a grade above
80.
11. You have a data frame containing the names, salaries and departments of employees. Using
Pandas, group the data frame by department and calculate the average salary and standard
deviation for each department.
12. You have a data frame containing the names, ages and genders of students. Using Pandas,
calculate the percentage of male and female students in each age group.
Page 6
PYTHON FOR MACHINE LEARNING (INT-215)
CA-1
Set-5
1. You have an array a of shape (5, 5) containing random values between 0 and 1. Using NumPy,
create a new array b that contains the same values as a, but with all values below 0.5 set to 0
and all values above or equal to 0.5 set to 1.
2. You have an array a of shape (4, 4) containing random integers between 0 and 9. Using NumPy,
create a new array b that contains the product of the even values in each row of a.
3. You have an array a of shape (3, 3) and a vector v of shape (3,). Using NumPy, create a new array
b that contains the product of a and v using broadcasting.
4. You have an array a of shape (3, 3) and an array b of shape (3, 1). Using NumPy, create a new
array c that contains the sum of a and b using broadcasting.
5. You have an array a of shape (2, 2) and an array b of shape (2, 2). Using NumPy, create a new
array c that contains the element-wise maximum of a and b.
6. You have an array a of shape (3, 3) containing random integers between 0 and 9. Using NumPy,
create a new array b that contains the indices of the maximum value in each row of a.
7. You have two arrays a and b of shape (3, 3) containing random integers between 0 and 9. Using
NumPy, create a new array c that contains the element-wise division of a and b, replacing any
division by 0 with NaN.
8. You have an array a of shape (3, 3) containing random integers between 0 and 9. Using NumPy,
create a new array b that contains the cumulative sum of the rows of a.
9. You have an array a of shape (3, 3) and an array b of shape (3, 3). Using NumPy, create a new
array c that contains the outer product of the first row of a and the first column of b.
10. You have a data frame containing the names, ages and occupations of individuals. Using Pandas,
create a new data frame that contains the top 5 most common occupations and their respective
frequencies.
11. You have a data frame containing the names, heights and weights of individuals. Using Pandas,
create a new data frame that contains the correlation between height and weight.
12. You have a data frame containing the names, ages and genders of students. Using Pandas,
calculate the average age and standard deviation for male and female students separately.
Page 7
PYTHON FOR MACHINE LEARNING (INT-215)
CA-1
Set-6
1. You have two arrays a and b of shape (3, 3) containing random integers between 0 and 9. Using
NumPy, create a new array c that contains the element-wise product of a and b, but only for
values where a is greater than 4.
2. You have an array a of shape (3, 3) containing random integers between 0 and 9. Using NumPy,
create a new array b that contains the inverse of a using the linalg module.
3. You have an array a of shape (3, 3) and a vector v of shape (3,). Using NumPy, create a new array
b that contains the dot product of a and v.
4. You have an array a of shape (3, 3) containing random integers between 0 and 9. Using NumPy,
create a new array b that contains the maximum value in each row of a.
5. You have two arrays a and b of shape (3, 3) containing random integers between 0 and 9. Using
NumPy, create a new array c that contains the element-wise difference between a and b.
6. You have an array a of shape (3, 3) containing random integers between 0 and 9. Using NumPy,
create a new array b that contains the sum of the diagonal of a.
7. You have an array a of shape (3, 3) containing random integers between 0 and 9. Using NumPy,
create a new array b that contains the exponential of each element in a.
8. You have an array a of shape (3, 3) and a vector v of shape (3,). Using NumPy, create a new array
b that contains the solution to the linear equation a x = v.
9. You have two arrays a and b of shape (3, 3) containing random integers between 0 and 9. Using
NumPy, create a new array c that contains the matrix product of a and b.
10. You have a data frame containing the names, ages and salaries of employees. Using Pandas,
create a new data frame that contains the mean and median salary for each age group.
11. You have a data frame containing the names, genders and salaries of employees. Using Pandas,
create a new data frame that contains the mean salary for male and female employees
separately, but only for employees whose salary is above the overall mean salary.
12. You have a data frame containing the names, ages and occupations of individuals. Using Pandas,
create a new data frame that contains the percentage of individuals in each age group for each
occupation.
Page 8
ROLL NO. WISE QUESTION SET ALLOCATION
Page 9
23 12107693 Manjusha Singh Yadav RK21MDA23 Set-5
Page 10
47 12110846 Chilla Jagadesh RK21MDB47 Set-5
Page 11
Page 12