Python for Data Science NPTEL Assignment 2

                     

Course name: Python for Data Science

Link to Enroll: Click Here

These are the answers for course Python for Data Science NPTEL Week 2 Assignment 2

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


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 the answers for course Python for Data Science NPTEL Week 2 Assignment 2


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 the answers for course Python for Data Science NPTEL Week 2 Assignment 2


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 the answers for course Python for Data Science NPTEL Week 2 Assignment 2


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 the answers for course Python for Data Science NPTEL Week 2 Assignment 2

Python for Data Science NPTEL All weeks: Click here

More NPTEL course answers: Click me

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


These are the answers for course Python for Data Science NPTEL Week 2 Assignment 2