Python for Data Science NPTEL | Week 2

Session: JAN-APR 2023

Course Name: Python for Data Science

Course Link: Click Here

These are NPTEL Python for Data Science Assignment 2 Answers


Q1. What will be the output of the following:

image 69

a. [[2 6 10]
[4 8 12]]
b. [[2 4 6]
[8 10 12]]
c. [[2 4]
[6 8]
[10 12]]
d. [[2 8]
[4 10]
[6 12]]

Answer: Update Soon


Q2. Let t1 = (1, 2, “tuple”, 4) and t2 = (5, 6, 7). Which of the following will not give any error after the execution?
a. t1.append(5)
b. x = t2[t1[1]]
c. t3 = t1 + t2
d. t3 = (t1, t2)
d. t3 = (list(t1), list(t2))

Answer: Update Soon


These are NPTEL Python for Data Science Assignment 2 Answers


Q3. Let d1 = {1 : “Pyhton”, 2 : [1, 2, 3]}. Which among the following will not give the error after the execution?
a. d1[2].append(4)
b. x = d1[0]
c. d1[“one”] = 1
d. d1.update({‘one’ : 2})

Answer: Update Soon


Q4. S1 = {1, 2, 3}
S2 = {5, 6, 3}
S1.add(4)
S2.add(“4”)
What will be the output of S1 − S2?

a. {1, 2, 3}
b. {1, 2, 3, 4}
c. {1, 2, “4”}
d. {1, 2, 4}

Answer: Update Soon


These are NPTEL Python for Data Science Assignment 2 Answers


Q5. S1 = “Hello” and S2 = “World”. Which of the following will not return “Hello world”?
a. S1 + “ ” + S2
b. S1[0 :] + “ ” + S2[0 :]
c. “{} {}”.format(S1, S2)
d. S1[: −1] + “ ” + S2[: −1]

Answer: Update Soon


Q6. Given a NumPy array, arr = np.array([[1, 9, 10], [3, 7, 6], [12, 8, 0]]), find the correct command from the following options to get an output array as [16 24 16]?
a. arr[1: 2]
b. np.sum(arr, axis = 0)
c. np.sum(arr, axis = 1)
d. np.sum([[1, 9, 10], [3, 7, 6], [12, 8, 0]])

Answer: Update Soon


These are NPTEL Python for Data Science Assignment 2 Answers


Q7. mat = np.matrix(“5, 9, 10; 2, 5, 4; 1, 9, 8; 2, 6, 8”)
mat1 = np.matrix(“1, 2, 3, 4”)
mat2 = np.insert(mat, 1, mat1, axis= 1)
print(mat2)
What will be the output of the above command?

a. [[5 2 1 2]
[1 2 3 4]
[9 5 9 6]]
[10 4 8 8]]
b. [[1 2 3 4]
[5 2 1 2]
[9 5 9 6]]
[10 4 8 8]]
c. [[5 1 9 10]
[2 2 5 4]
[1 3 9 8]]
[2 4 6 8]]
d. It will give an error.

Answer: Update Soon


Q8. student = {‘name’: ‘Jane’, ‘age’: 25, ‘courses’: [‘Math’, ‘Statistics’]}
Which among the following will return
{‘name’: ‘Jane’, ‘age’: 26, ‘courses’: [‘Math’, ‘Statistics’], ‘phone’: ‘123-456’}

a. student.update({‘age’ : 26})
b. student.update({‘age’ : 26, ‘phone’: ‘123-456’})
c. student[‘phone’] = ‘123-456’
d. student.update({‘age’ : 26})
e. None of the above

Answer: Update Soon


These are NPTEL Python for Data Science Assignment 2 Answers


Q9. c = np.arange(start = 1, stop = 20, step = 3). What is c[5]?
a. 13
b. 16
c. 15
d. 12

Answer: Update Soon


Q10. Which of the following data type is immutable?
a. list
b. set
c. tuple
d. dictionary

Answer: Update Soon


These are NPTEL Python for Data Science Assignment 2 Answers

More Weeks of Python for Data Science NPTEL: Click here

More NPTEL courses: https://progiez.com/nptel


Session: JULY-DEC 2022

Q1. Which of the following function(s) can be used to resize a NumPy array in Python from the given options.
a. array.shape(reshape)
b. array.reshape(shape)
c. numpy.reshape(array, shape)
d. numpy.reshape(shape, array)

Answers: b, c


These are NPTEL Python for Data Science Assignment 2 Answers


2. Create the tuples given below:
tuple_1 = (1,5,6,7,8)
tuple_2 = (8,9,4)

Identify which of the following options does not work on the given tuples

a. sum(tuple_1)
b. len(tuple_2)
c. tuple_2 + tuple_1
d. tuple_1[3] = 45

Answers: d. tuple_1[3] = 45


3. Create a sequence of numbers from 15 to 25 and increment by 4. What is the index of the element 19?
a. 3
b. 2
c. 0
d. 1

Answers: d. 1


These are NPTEL Python for Data Science Assignment 2 Answers


4. Consider a variable job = “chemist”. Which of the following expression(s) will retrieve the last character from the string?

a. job[7]
b. job[len(job) – 1]
c. job[5:6]
d. job[- 1]

Answers: b, c


5. Given a list, ls = [1, 2, 3, 3, 2, 3, 1, 4, 5, 6, 5, 6, 3, 2, 1, 1, 1, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 10, 10, 1, 2, 3, 9, 10], which of the following would be the most efficient method in determining the unique elements present in ls?
a. By converting ls into a NumPy array, and applying relevant methods
b. By converting ls into a set
c. By iterating through ls, and doing appropriate manipulations
d. None of the above

Answers: b. By converting ls into a set


These are NPTEL Python for Data Science Assignment 2 Answers


6. Which of the following data structure(s) can be used as a key while creating a dictionary?
a. list
b. str
c. set
d. None

Answers: b. str


7. Given a dictionary, states = {‘Tamil Nadu’: ‘TN’, ‘Karnataka’: ‘KA’, ‘Kerala’: ‘KL’, ‘Maharashtra’: ‘MH’}, which of the following command(s) is used to remove the key-value pair ‘Karnataka’: ‘KA’ from it?
a. del states[‘Karnataka’]
b. states.popitem(‘Karnataka’)
c. states.pop(‘Karnataka’)
d. del states[‘Karnataka’:’KA’]

Answers: c. states.pop(‘Karnataka’)


8. Which of the following is valid to declare a string literal Shin’ichi to a variable?
a. “Shin’ichi”
b. ‘Shin”ichi’‘
c. Shin’ichi’
d. None of the above

Answers: a. “Shin’ichi”


These are NPTEL Python for Data Science Assignment 2 Answers


9. Which of the following commands can be used to create a NumPy array?
a. np.array()
b. np.zeros()
c. np.empty()
d. All of the above

Answers: d. All of the above


10. Given a NumPy array, arr = np.array([[5,9,10], [7,2,6], [12,8,0]]), find the correct command from the following options to get an output array as [24 15 20]?

a. np.sum(arr)
b. np.sum(arr, axis = 0)
c. np.sum(arr, axis = 1)
d. None of the above

Answers: c. np.sum(arr, axis = 1)


These are NPTEL Python for Data Science Assignment 2 Answers

More Weeks of Python for Data Science NPTEL: Click here

More NPTEL courses: https://progiez.com/nptel

* The material and content uploaded on this website are for general information and reference purposes only. Please do it by your own first. COPYING MATERIALS IS STRICTLY PROHIBITED.


More from PROGIEZ

These are NPTEL Python for Data Science Assignment 2 Answers