WorksheetsPython and NumPy Quiz
Total questions: 44
Worksheet time: 38mins
Which of the following is mutable?
tuple
string
list
int
What does len("Hello\nWorld") return?
10
11
12
9
What is the output of print(3 * 'abc')?
abcabcabc
abc3
abc abc abc
Error
Which keyword is used to define a function in Python?
func
define
def
function
What is the output of bool([])?
True
False
None
Error
Which of the following will raise an error?
int("123")
int("12.3")
int(12.3)
int(True)
What is the output of print("Python"[::-1])?
nohtyP
Python
nothyP
Error
Which of the following is not a valid Python data type?
set
dict
array
list
What is the output of print(2 ** 3 ** 2)?
64
512
256
8
Which function creates an array of zeros?
np.zeros()
np.empty()
np.ones()
np.full()
What is the output of np.array([1, 2, 3]).shape?
(3,)
(1,3)
(3,1)
[3]
Which function returns evenly spaced values over a specified interval?
np.linspace()
np.arange()
np.range()
np.split()
What does np.eye(3) produce?
Identity matrix
Diagonal matrix
Zero matrix
Error
What is the output of np.array([1, 2, 3]) + np.array([4, 5, 6])?
[5, 7, 9]
[1, 2, 3, 4, 5, 6]
Error
[4, 5, 6]
Which method flattens a NumPy array?
flatten()
reshape(-1)
ravel()
All of the above
What is the output of np.arange(1, 5, 2)?
[1, 3]
[1, 2, 3, 4]
[1, 3, 5]
[1, 2, 5]
Which function computes the mean of an array?
np.mean()
np.average()
np.median()
np.sum()
What does np.dot() do?
Element-wise multiplication
Matrix multiplication
Transpose
Scalar multiplication
Which of the following raises an error? python a = np.array([1, 2]) b = np.array([[1, 2], [3, 4]]) print(a + b)
[2, 4], [4, 6]
Error
[2, 4]
[1, 2, 3, 4]
What is the output of np.array([[1,2],[3,4]]).T?
[[1,3],[2,4]]
[[1,2],[3,4]]
[[2,1],[4,3]]
Error
Which function returns the maximum value in an array?
np.max()
np.maximum()
np.argmax()
np.sort()
What is the output of np.array([1,2,3]) > 2?
[False, False, True]
[True, True, False]
[1,2,3]
Error
Which function stacks arrays vertically?
np.vstack()
np.hstack()
np.stack()
np.concat()
What is the output of np.array([1,2,3]).dtype?
int64
float64
object
str
Which function is used to plot a line graph?
plt.plot()
plt.line()
plt.graph()
plt.show()
What does plt.show() do?
Displays the plot
Saves the plot
Clears the plot
Creates a figure
Which function sets the title of a plot?
plt.title()
plt.set_title()
plt.name()
plt.heading()
What is the output of this code? python import matplotlib.pyplot as plt plt.plot([1,2,3],[4,5,6]) plt.show()
Line graph from (1,4) to (3,6)
Bar chart
Error
Empty plot
Which function adds a legend to the plot?
plt.legend()
plt.label()
plt.key()
plt.info()
What does plt.xlabel("X-axis") do?
Sets label for x-axis
Sets label for y-axis
Sets title
Adds legend
Which function creates a histogram?
plt.hist()
plt.bar()
plt.plot()
plt.scatter()
What does plt.savefig("plot.png") do?
Saves the plot as PNG
Displays the plot
Deletes the plot
Converts plot to array
What is the output of np.array([[1, 2], [3, 4]]).flatten()?
[1, 3, 2, 4]
Error
[1, 2, 3, 4]
[[1, 2], [3, 4]]
Which function is used to create a scatter plot?
plt.bar()
plt.plot()
plt.scatter()
plt.hist()
What is the output of len([1, 2, 3, 4])?
5
Error
3
4
What does plt.ylabel("Y-axis") do?
Adds grid
Sets title
Sets label for x-axis
Sets label for y-axis
Which function is used to concatenate two arrays?
np.join()
np.merge()
np.append()
np.concatenate()
What is the output of np.zeros((2, 3))?
[[1, 1, 1], [1, 1, 1]]
[[2, 2, 2], [2, 2, 2]]
Error
[[0, 0, 0], [0, 0, 0]]
What does plt.ylabel("Y-axis") do?
Adds grid
Sets label for y-axis
Sets label for x-axis
Sets title
Which function is used to create a bar chart?
plt.bar()
plt.plot()
plt.scatter()
plt.hist()
What is the output of np.array([[1, 2], [3, 4]]).sum()?
Error
[1, 2, 3, 4]
10
7
Which function generates a sequence of numbers?
np.range()
np.linspace()
np.arange()
np.sequence()
What does np.unique() do?
Reshapes an array
Counts elements in an array
Sorts an array
Finds unique elements in an array
Which function is used to concatenate two arrays?
np.join()
np.merge()
np.append()
np.concatenate()
