Font size
WorksheetsSeason 5 #Spaic Python Weekly Quiz
Total questions: 20
Worksheet time: 11mins
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)
array(np.nan,2,3,4,5)
array([np.nan,2,3,4,5])
np.array([np.nan,2,3,4,5])
All the above
To create c copy of an array a = np.array([0, 1])
in Numpy
c = a
c = a.copy()
All the above
How to create an array using Numpy for a list from 0 to 4
arr=np.array([0,1,2,3,4])
arr = np.arange(5)
arr = np.arange(0, 5, 1)
arr=np.array(0,1,2,3,4)
How to specifie the number of element to return in an array using NumPy
np.linspace(a, b, num=c)
np.array(a, b, num=c)
To transpose the value of an array in Numpy (arr = np.arange(8)) we can use (transposed = np.transpose(arr))
True
False
How to create an array of 5 elements, all of which are 0/1 in Numpy
np.zeros(5) / np.ones(5)
np.array([0,0,0,0,0] )/ np.array([1,1,1,1,1])
np.arange(0)/np.arange(1)
What does the arange function do in Numpy?
Returns a 1-D array of numbers based on a a given range and interval
Returns a random array
Squares each value of an array
Returns the largest element of an array
What happens if we try to use np.save on a file without a .npy extension in Numpy?
The function raises an exception
The data is saved to the file without the .npy extension
The function automatically adds the .npy extension
The function does nothing
What is the difference between np.sum and np.cumsum in Numpy?
The former is computationally more expensive than the latter
Both perform the same thing
The former is significantly slower than the latter
The former produces the overall sum while the latter calculates cumulative sums
Consider the 2-D array, arr. What is the output of np.sum(arr, axis=1)?
A 1-D array containing the column sums of arr
A 1-D array containing the row sums of arr
A 2-D array containing the cumulative column sums of arr
A 1-D array containing the cumulative row sums of arr
What is the default for axis in the Pandas drop function (pandas.DataFrame.drop)
0
1
What does the following function get_element return when the input is lst = [1, 7, 3, 5]?
1
9
7
25
49
What is the output of the following code?
my_dict = {'peaches':'cream', 'cat':'meow', 'this one':'which one'}
my_dict['this one']
‘dog’
‘which one’
{‘which one’}
‘this one: which one’
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 plot is outputted and saved as 'new_plot'.
The function returns a plot.
nothing
In python, lists and numpy arrays can have different data types as elements
True
False
True for lists, not numpy arrays
True for numpy arrays , not lists
my_list = [1,2,3] ,my_array = np.array[1,2,3]
Which of the following will return an error?
my_array/3
my_list/3
You want to rename the columns in a dataframe to ‘old_customers’ and ‘new_customers’.How would you do that
df.rename( columns =[‘col1’=[‘old_customers’],’col2’=[‘new_customers’])
df.rename(columns ={‘col1’: ‘old_custmers’,’col2’ = ‘new_customers’})
Which of these will return descriptive statistics for a numeric Series ‘s’?
Series.describe()
describe(s)
s.describe()
s.descriptive_stats()
Select all that apply: Which will produce a histogram of the numeric Series ‘s’
sns.distplot(s)
sns.hist(a=s)
Which of the following are methods for indexing into a DataFrame?
Use the loc and iloc functions
Directly index columns similar to a Python dictionary
Using slices to retrieve a set of rows
All of the above
