CARVIEW |
Slicing & Indexing in NumPy
This quiz is set of questions for the topic Slicing & Indexing in NumPy, starting from basic and progressing to more advanced concepts.
Question 1
What is the output of the following code?
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr[0])
5
0
1
IndexError
Question 2
What will be the output of this code?
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr[-1])
IndexError
-1
5
1
Question 3
Given the following code, what will be the output?
import numpy as np
arr = np.array([10, 20, 30, 40, 50])
print(arr[1:4])
[10, 20, 30]
[20, 30, 40]
[20, 30, 40, 50]
[20, 30]
Question 4
What does the following code do?
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr[::2])
[1, 3, 5]
[2, 4]
[1, 2, 3, 4, 5]
[3, 5]
Question 5
What will be the output of the following code?
import numpy as np
arr = np.array([5, 10, 15, 20, 25])
print(arr[1:4:2])
[10, 15, 20]
[10, 20]
[20, 25]
[5, 10, 15]
Question 6
What is the output of the following code?
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr[1, 2])
4
5
6
IndexError
Question 7
What will be the result of this code?
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr[:, 1])
[1, 2]
[1, 4]
[2, 5]
[1, 3, 5]
Question 8
What will be the output of the following code?
import numpy as np
arr = np.array([[1, 2], [3, 4], [5, 6]])
print(arr[1:, :1])
[[1], [3], [5]]
[[2], [4], [6]]
[[3], [5]]
[[1], [2], [3], [4], [5], [6]]
Question 9
What will be the output of the following code?
import numpy as np
arr = np.array([10, 20, 30, 40, 50])
print(arr[1:4][::-1])
[40, 30, 20]
[30, 40, 50]
[10, 20, 30]
[50, 40, 30]
Question 10
What will be the result of the following code?
import numpy as np
arr = np.array([[1, 2], [3, 4], [5, 6]])
print(arr[::2, 1:])
[[2], [6]]
[[1, 2], [5, 6]]
[[1], [3], [5]]
[[2], [4]]
There are 10 questions to complete.