### Python for Data Science NPTEL | Week 2

Session: JAN-APR 2023

Course Name: Python for Data Science

#### Q1. What will be the output of the following:

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]]

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]
c. t3 = t1 + t2
d. t3 = (t1, t2)
d. t3 = (list(t1), list(t2))

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.append(4)
b. x = d1
c. d1[“one”] = 1
d. d1.update({‘one’ : 2})

Q4. S1 = {1, 2, 3}
S2 = {5, 6, 3}
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}

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]

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]])

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.

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

These are NPTEL Python for Data Science Assignment 2 Answers

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

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

These are NPTEL Python for Data Science Assignment 2 Answers

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)

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 = 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

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
b. job[len(job) – 1]
c. job[5:6]
d. job[- 1]

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

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’]

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

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 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.