wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Season 5 #Spaic Python Weekly Quiz

Total questions: 20

Worksheet time: 11mins

Name
Class
Date
1.

How to create an array using Numpy for this list (np.nan as the first element, and the next element are integers from 2 to 5)

a)

array(np.nan,2,3,4,5)

b)

array([np.nan,2,3,4,5])

c)

np.array([np.nan,2,3,4,5])

d)

All the above

2.

To create c copy of an array a = np.array([0, 1])

in Numpy

a)

c = a

b)

c = a.copy()

c)

All the above

3.

How to create an array using Numpy for a list from 0 to 4

a)

arr=np.array([0,1,2,3,4])

b)

arr = np.arange(5)

c)

arr = np.arange(0, 5, 1)

d)

arr=np.array(0,1,2,3,4)

4.

How to specifie the number of element to return in an array using NumPy

a)

np.linspace(a, b, num=c)

b)

np.array(a, b, num=c)

5.

To transpose the value of an array in Numpy (arr = np.arange(8)) we can use (transposed = np.transpose(arr))

a)

True

b)

False

6.

How to create an array of 5 elements, all of which are 0/1 in Numpy

a)

np.zeros(5) / np.ones(5)

b)

np.array([0,0,0,0,0] )/ np.array([1,1,1,1,1])

c)

np.arange(0)/np.arange(1)

7.

What does the arange function do in Numpy?

a)

Returns a 1-D array of numbers based on a a given range and interval

b)

Returns a random array

c)

Squares each value of an array

d)

Returns the largest element of an array

8.

What happens if we try to use np.save on a file without a .npy extension in Numpy?

a)

The function raises an exception

b)

The data is saved to the file without the .npy extension

c)

The function automatically adds the .npy extension

d)

The function does nothing

9.

What is the difference between np.sum and np.cumsum in Numpy?

a)

The former is computationally more expensive than the latter

b)

Both perform the same thing

c)

The former is significantly slower than the latter

d)

The former produces the overall sum while the latter calculates cumulative sums

10.

Consider the 2-D array, arr. What is the output of np.sum(arr, axis=1)?

a)

A 1-D array containing the column sums of arr

b)

A 1-D array containing the row sums of arr

c)

A 2-D array containing the cumulative column sums of arr

d)

A 1-D array containing the cumulative row sums of arr

11.

What is the default for axis in the Pandas drop function (pandas.DataFrame.drop)

a)

0

b)

1

12.

What does the following function get_element return when the input is lst = [1, 7, 3, 5]?

a)

1

b)

9

c)

7

d)

25

e)

49

13.

What is the output of the following code?

my_dict = {'peaches':'cream', 'cat':'meow', 'this one':'which one'}

my_dict['this one']

a)

‘dog’

b)

‘which one’

c)

{‘which one’}

d)

‘this one: which one’

14.

What happens when the function save_plot is called?

import matplotlib.pyplot as plt


def save_plot(x, y):

plt.plot(x, y)

plt.savefig('new_plot')

a)

A plot is outputted and saved as 'new_plot'.

b)

The function returns a plot.

c)

nothing

15.

In python, lists and numpy arrays can have different data types as elements

a)

True

b)

False

c)

True for lists, not numpy arrays

d)

True for numpy arrays , not lists

16.

my_list = [1,2,3] ,my_array = np.array[1,2,3]

Which of the following will return an error?

a)

my_array/3

b)

my_list/3

17.

You want to rename the columns in a dataframe to ‘old_customers’ and ‘new_customers’.How would you do that

a)

df.rename( columns =[‘col1’=[‘old_customers’],’col2’=[‘new_customers’])

b)

df.rename(columns ={‘col1’: ‘old_custmers’,’col2’ = ‘new_customers’})

18.

Which of these will return descriptive statistics for a numeric Series ‘s’?

a)

Series.describe()

b)

describe(s)

c)

s.describe()

d)

s.descriptive_stats()

19.

Select all that apply: Which will produce a histogram of the numeric Series ‘s’

a)

sns.distplot(s)

b)

sns.hist(a=s)

20.

Which of the following are methods for indexing into a DataFrame?

a)

Use the loc and iloc functions

b)

Directly index columns similar to a Python dictionary

c)

Using slices to retrieve a set of rows

d)

All of the above