NumPy – Python Package for Data MCQ solution
1. Which of the following characters are used to represent an unordered list?
Ans:- All of those mentioned
2. Which of the following is a Scientific distribution of Python, used for Data Science?
Ans:- All of those mentioned
3. It is possible to embed code snippets in markdown. State True or False?
Ans:- TRUE
4. A line magic methods starts with ______ ?
Ans:- %
5. A cell magic methods starts with ______ ?
Ans:- %%
6. Which language is used to write documentation in a Jupyter Notebook?
Ans:- MARKDOWN
7. Which of the following magic method list the history of input commands ?
Ans:- %hist
8. Which of the following is used to know about an object in Ipython?
Ans:- ?
9. Which of the following is used to run system commands from Ipython?
Ans:- !
10. What is the basic element of a Jupyter Notebook ?
Ans:- Cell
11. What is the input of a cell magic method ?
Ans:- Python code written in multiple lines of a single cell.
12. How to write the word ‘Python’ in markdown, to emphasize it in bold ?
Ans:- **Python**
13. Which of the following is Ture about Numpy array data elements?
Ans:- Data elements are of same type and of fixed size
14. Which of the following attribute determine the number of dimensions of a ndarray?
Ans:- ndim
15. Which of the following attribute returns total number of bytes consumed by a ndarray?
Ans:- nbytes
16. What does flags attribute of an ndarray return?
Ans:- Memory layout of a ndarray
17. Which of the following attribute returns the number of elements in each dimension of a multi dimensional array?
Ans:- num
18. What is the output of the following code?
import numpy as np
x = np.array([[3.2, 7.8, 9.2],
[4.5, 9.1, 1.2]], dtype=’int64′)
print(x.itemsize)
Ans:- 8
19. What is the output of the following code?
import numpy as np
y = np.array([3+4j, 0.4+7.8j])
print(y.dtype)
Ans:- complex128
20. Which of the following method is used to read data from a text file?
Ans:- loadtxt
21. What is the output of the following code ?
Ans:- [[ 1. 0.] [ 0. 1.]]
22. Which of the following expressions return an Error?
1. np.random.rand(3, 2)
2. np.random.random(3, 2)
import numpy as np
z = np.eye(2)
print(y)
Ans:- 2
23. What is the output of the following code ?
import numpy as np
x = np.array([[-1,0,1], [-2, 0, 2]])
y = np.zeros_like(x)
print(y)
Ans:- [[0 0 0] [0 0 0]]
24. Which of the following numpy method is used to simulate a binomial distribution?
Ans:- binomial
25. What is the output of the following code ?
import numpy as np
print(np.linspace(1, 10, 5))
print(np.arange(1, 10, 5))
Ans:- [ 1. 3.25 5.5 7.75 10. ] [1 6]
26. What is the output of the following code ?
import nupy as np
print(np.array(([1, 2], (3,4))).shape)
Ans:- (2,2)
27. Predict the number of rows and columns of array x defined below?
import numpy as np
x = np.arange(20).reshape(4, 5)
Ans:- 4, 5
28. What is the output of the following code ?
import numpy as np
x = np.arange(6).reshape(2,3)
y = np.hsplit(x,(2,))
print(y[0])
Ans:- [[0 1] [3 4]]
29. Which of the following numpy method is used to join arrays horizontally ?
Ans:- hstack
30. What is the shape of array x defined below?
import numpy as np
x = np.arange(20).reshape(10, 10)
Ans:- Results in Error while creating
31. What is the output of the following code?
import numpy as np
x = np.arange(4).reshape(2,2)
y = np.vsplit(x,2)
print(y[0])
Ans:- [[0 1]]
32. Array x is defined below. Determine the number of elements of it contains in second dimension?
Ans:- 15
import numpy as np
x = np.arange(90).reshape(3, 15, 2)
33. What is the output of the following code ?
import numpy as np
x = np.arange(4).reshape(2,2)
y = np.arange(4, 8).reshape(2,2)
print(np.hstack((x,y)))
Ans:- [[0 1 4 5] [2 3 6 7]]
34. Which of the following numpy method is used to join arrays vertically ?
Ans:- vstack
35. Which of the following method is used to convert the data type of an array?
Ans:- astype
36. Which of the following method is used to check if a number is an infinite or not ?
Ans:- isinfinite
37. What is the shape of Broadcasting array resulted from arrays with shapes (4, 1, 1,7) and (3, 1) ?
Ans:- (4, 1, 3, 7)
38. What is the output of the following Code?
import numpy as np
x = np.arange(4)
y = np.arange(4)
print(x == y)
Ans:- FALSE
39. What is the output of the following code ?
import numpy as np
x = np.arange(20).reshape(4,5)
print(x.mean(axis=1))
Ans:- [ 2. 7. 12. 17.]
40. What is the output of the following Code?
import numpy as np
x = np.arange(4)
print(x**2)
Ans:- [0 1 4 9]
41. Is Broadcasting feasible between two arrays whose shapes are (5, 8, 2) and (2,) ?
Ans:- Yes
42. Is Broadcasting feasible between two arrays whose shapes are (5, 8, 1) and (4, 2) ?
Ans:- No
43. What is the ouput of the following code?
import numpy as np
x = np.arange(4).reshape(2,2)
print(np.isfinite(x))
Ans:- FALSE
44. What is the output of the following code?
import numpy as np
print(np.repeat(3, 4))
Ans:- [3 3 3 3]
45. What is the output of the following code ?
import numpy as np
x = np.arange(4).reshape(2,2)
print(x.tolist())
Ans:- [[0, 1], [2, 3]]
46. What is the outout of the following code ?
import numpy as np
x = np.array([[-2],
[2]])
y = np.array([[-3, 3]])
print(x.dot(y))
Ans:- [[ 6 -6] [-6 6]]
47. What is the outout of the following code ?
import numpy as np
x = np.array([[-2],
[2]])
y = np.array([[-3, 3]])
print(x + y)
Ans:- [[-5 1] [-1 5]]
48. What is the output of the following code?
import numpy as np
x = np.arange(30).reshape(5,6)
print(x.argmax(axis=1))
Ans:- [4 4 4 4 4]
49. What is the shape of Broadcasting array resulted from arrays with shapes (9, 2, 1, 5) and (3, 1) ?
Ans:- (9, 2, 3, 5)
50. What is the output of the following code?
import numpy as np
x = np.arange(30).reshape(3,5,2)
print(x[-1, 2:-1, -1])
Ans:- [25 27]
51. What is the output of the following code?
import numpy as np
x = np.array([[0, 1], [1, 1], [2, 2]])
y = x.sum(-1)
print(x[y < 2, :])
Ans:- [[0 1]]
52. What is the output of the following code?
import numpy as np
x = np.array([[1, 2], [3, 4], [5, 6]])
print(x[[0, 1, 2], [0, 1, 1]])
Ans:- [1 4 6]
53. What is the output of the following code?
import numpy as np
x = np.array([[0, 1], [1, 1], [2, 2]])
print(x.sum(-1))
Ans:- [1 2 4]
54. What is the output of the following code?
import numpy as np
x = np.arange(30).reshape(3,5,2)
print(x[1,::2,1])
Ans:- [11 15 19]
55. What is the output of the following code?
import numpy as np
x = np.arange(12).reshape(3,4)
print(x[:,1])
Ans:- [1 5 9]
56. What is the output of the following code?
import numpy as np
x = np.arange(4)
print(x.flatten())
Ans:- [0 1 2 3]
57. What is the output of the following code?
import numpy as np
x = np.arange(12).reshape(3,4)
print(x[-2])
Ans:- [4 5 6 7]
58. What is the output of the following code?
import numpy as np
x = np.arange(30).reshape(3,5,2)
print(x[1][::2][1])
Ans:- [14 15]
59. What is the output of the following code?
import numpy as np
x = np.array([[0, 1], [1, 1], [2, 2]])
print(x.sum(-1))
Ans:- [1 2 4]
60. What is the output of the following code?
import numpy as np
x = np.arange(12).reshape(3,4)
print(x[-1:,].shape)
Ans:- (1, 4)