
1. What is NumPy?
a. A programming language
b. A numerical computing library
c. A database management system
Answer: b
2. Which of the following is not a data type supported by NumPy?
a. integer
b. float
c. string
Answer: c
3. How can you create a NumPy array?
a. Using the array() function
b. Using the zeros() function
c. Using the ones() function
d. All of the above
Answer: d
4. Which of the following functions can you use to generate a sequence of evenly spaced numbers over a specified range?
a. linspace()
b. arange()
c. logspace()
Answer: b
5. What is the output of the following code?
import numpy as np
x = np.array([1, 2, 3, 4, 5])
print(x[2])
a. 1
b. 2
c. 3
d. 4
e. 5
Answer: c
6. What is the output of the following code?
import numpy as np
x = np.array([[1, 2], [3, 4]])
print(x.shape)
a. (2, 2)
b. (4,)
c. (2,)
d. (2, 1)
Answer: a
7. How can you perform element-wise multiplication of two NumPy arrays?
a. Using the * operator
b. Using the dot() function
c. Using the multiply() function
Answer: a
8. What is the output of the following code?
import numpy as np
x = np.array([1, 2, 3, 4, 5])
y = x[2:4]
print(y)
a. [1, 2]
b. [2, 3]
c. [3, 4]
d. [4, 5]
Answer: c
9. Which of the following functions can you use to find the minimum value of a NumPy array?
a. min()
b. amax()
c. argmin()
Answer: a
10. How can you concatenate two NumPy arrays horizontally?
a. Using the vstack() function
b. Using the hstack() function
c. Using the concatenate() function with axis=1
Answer: b
11. What is the output of the following code?
import numpy as np
x = np.array([1, 2, 3, 4, 5])
y = x.reshape(5, 1)
print(y.shape)
a. (5, 1)
b. (1, 5)
c. (1, 1, 5)
d. (5,)
Answer: a
12. Which of the following functions can you use to find the index of the maximum value of a NumPy array?
a. argmax()
b. max_index()
c. max_idx()
Answer: a
13. How can you perform matrix multiplication of two NumPy arrays?
a. Using the * operator
b. Using the dot() function
c. Using the multiply() function
Answer: b
14. What is the output of the following code?
import numpy as np
x = np.array([1, 2, 3, 4, 5])
y = x[1::2]
print(y)
a. [1, 3, 5]
b. [2, 4]
c. [2, 4, 5]
d. [1, 2, 3, 4, 5]
Answer: b
15. Which of the following functions can you use to find the sum of a NumPy array?
a. sum()
b. mean()
c. std()
Answer: a
16. How can you find the transpose of a NumPy array?
a. Using the transpose() function
b. Using the reshape() function with axis=1
c. Using the swapaxes() function
Answer: a
17. What is the output of the following code?
import numpy as np
x = np.array([[1, 2], [3, 4]])
y = np.array([[5, 6], [7, 8]])
z = np.concatenate((x, y), axis=1)
print(z)
a. [[1, 2, 5, 6], [3, 4, 7, 8]]
b. [[1, 5], [2, 6], [3, 7], [4, 8]]
c. [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
Answer: a
18. How can you get a diagonal array from a NumPy array?
a. Using the diag() function
b. Using the diagonal() function
c. Using the trace() function
Answer: b
19. What is the output of the following code?
import numpy as np
x = np.array([[1, 2], [3, 4]])
y = x.flatten()
print(y)
a. [1, 2, 3, 4]
b. [[1, 2], [3, 4]]
c. [1, 3, 2, 4]
d. [1, 1, 2, 3, 4]
Answer: a
20. Which of the following functions can you use to find the maximum value of a NumPy array?
a. amax()
b. max()
c. argmax()
Answer: a
21. How can you access elements from a two-dimensional NumPy array?
a. Using the [] operator with the row and column indexes
b. Using the () operator with the row and column indexes
c. Using the [] operator with a tuple containing the row and column indexes
Answer: c
22. What is the output of the following code?
import numpy as np
x = np.array([1, 2, 3, 4, 5])
y = x[:-2]
print(y)
a. [1, 2]
b. [1, 2, 3]
c. [1, 2, 3, 4]
d. [1, 2, 3, 4, 5]
Answer: c
23. How can you create a NumPy array with random values?
a. Using the random() function
b. Using the rand() function
c. Using the randint() function
Answer: b
24. What is the output of the following code?
import numpy as np
x = np.array([[1, 2], [3, 4]])
y = np.array([[5, 6], [7, 8]])
z = np.dot(x, y)
print(z)
a. [[5, 6], [21, 24]]
b. [[7, 8], [15, 18]]
c. [[1, 2, 5, 6], [3, 4, 7, 8]]
Answer: a
25. Which of the following functions can you use to find the square root of a NumPy array?
a. sqrt()
b. pow()
c. exp()
Answer: a
26. How can you perform element-wise division of two NumPy arrays?
a. Using the / operator
b. Using the dot() function
c. Using the divide() function
Answer: a
27. What is the output of the following code?
import numpy as np
x = np.array([1, 2, 3, 4, 5])
y = x[[0, 2, 4]]
print(y)
a. [1, 3, 5]
b. [2, 4]
c. [1, 2, 3, 4, 5]
d. [0, 2, 4]
Answer: a
28. Which of the following functions can you use to find the mean value of a NumPy array?
a. mean()
b. median()
c. min()
Answer: a
29. How can you sort a NumPy array?
a. Using the sort() function
b. Using the argsort() function
c. Using the searchsorted() function
Answer: a
30. What is the output of the following code?
import numpy as np
x = np.array([1, 2, 3, 4, 5])
y = np.delete(x, [1, 3])
print(y)
a. [1, 2, 4, 5]
b. [1, 3, 5]
c. [2, 4]
Answer: a
31. How can you perform element-wise addition of two NumPy arrays?
a. Using the + operator
b. Using the dot() function
c. Using the add() function
Answer: a
32. What is the output of the following code?
import numpy as np
x = np.array([[1, 2], [3, 4]])
y = np.array([[5, 6], [7, 8]])
z = np.maximum(x, y)
print(z)
a. [[5, 6], [7, 8]]
b. [[1, 2], [3, 4]]
c. [[5, 6], [7, 8], [1, 2], [3, 4]]
Answer: a
33. How can you access a row from a two-dimensional NumPy array?
a. Using the [] operator with the row index
b. Using the () operator with the row index
c. Using the [] operator with a tuple containing the row index and slice operator
Answer: a
34. What is the output of the following code?
import numpy as np
x = np.array([[1, 2], [3, 4]])
y = np.array([5, 6])
z = np.dot(x, y)
print(z)
a. [11, 17]
b. [[11], [17]]
c. [[5, 6], [10, 12]]
Answer: a
35. Which of the following functions can you use to find the standard deviation of a NumPy array?
a. var()
b. std()
c. mean()
Answer: b
36. How can you perform matrix addition of two NumPy arrays?
a. Using the + operator
b. Using the dot() function
c. Using the add() function
Answer: a
37. What is the output of the following code?
import numpy as np
x = np.array([[1, 2], [3, 4], [5, 6]])
y = x[1:]
print(y)
a. [[3, 4], [5, 6]]
b. [[1, 2], [3, 4]]
c. [[5, 6]]
Answer: a
38. Which of the following functions can you use to find the cumulative sum of a NumPy array?
a. cumsum()
b. diff()
c. percentile()
Answer: a
39. How can you calculate the dot product of two NumPy arrays?
a. Using the * operator
b. Using the dot() function
c. Using the multiply() function
Answer: b
40. What is the output of the following code?
import numpy as np
x = np.array([1, 2, 3, 4, 5])
y = x[::2]
print(y)
a. [1, 3, 5]
b. [2, 4]
c. [1, 2, 3, 4, 5]
Answer: a
41. Which of the following functions can you use to find the variance of a NumPy array?
a. var()
b. std()
c. mean()
Answer: a
42. How can you calculate the mean value of each column of a two-dimensional NumPy array?
a. Using the mean() function with axis=0
b. Using the mean() function with axis=1
c. Using the mean() function with no axis specified
Answer: a
43. What is the output of the following code?
import numpy as np
x = np.array([[1, 2], [3, 4]])
y = x > 2
print(y)
a. [[False, False], [False, True]]
b. [[1, 2], [3, 4]]
c. [[False], [True], [False], [True]]
Answer: a
44. How can you perform matrix subtraction of two NumPy arrays?
a. Using the – operator
b. Using the dot() function
c. Using the subtract() function
Answer: a
45. What is the output of the following code?
import numpy as np
x = np.array([[1, 2], [3, 4]])
y = x[::-1]
print(y)
a. [[1, 3], [2, 4]]
b. [[4, 3], [2, 1]]
c. [[3, 1], [4, 2]]
Answer: c
46. Which of the following functions can you use to find the median value of a NumPy array?
a. median()
b. mean()
c. min()
Answer: a
47. How can you calculate the sum of each row of a two-dimensional NumPy array?
a. Using the sum() function with axis=0
b. Using the sum() function with axis=1
c. Using the sum() function with no axis specified
Answer: b
48. What is the output of the following code?
import numpy as np
x = np.array([1, 2, 3, 4, 5])
y = np.where(x > 3)
print(y)
a. (array([0, 1, 2, 3]),)
b. (array([3, 4]),)
c. (array([4, 5]),)
Answer: b
49. How can you calculate the product of each column of a two-dimensional NumPy array?
a. Using the prod() function with axis=0
b. Using the prod() function with axis=1
c. Using the prod() function with no axis specified
Answer: a
50. What is the output of the following code?
import numpy as np
x = np.array([1, 2, 3, 4, 5])
y = np.argsort(x)
print(y)
a. [5, 4, 3, 2, 1]
b. [0, 1, 2, 3, 4]
c. [4, 3, 2, 1, 0]
Answer: b
- Top 10 DevOps Trainers in the world - October 7, 2023
- What is Cookies and Why it is Used? - May 24, 2023
- TOP trends of transitions in TikTok - May 10, 2023