Question 1
Which function is used to create a NumPy array from a list?
np.create()
np.array()
np.list()
np.arraylist()
Question 2
Which of the following code snippets will create a NumPy array with the values [1,2,3,4]?
np.array([1, 2, 3, 4])
np.create([1, 2, 3, 4])
np.array([1, 2, 3, 4], type=int)
np.list([1, 2, 3, 4])
Question 3
Given the following code, what will be the output?
import numpy as np
arr = np.array([1, 2, 3, 4], dtype=float)
print(arr)
[1 2 3 4]
[1. 2. 3. 4]
[1.0 2.0 3.0 4.0]
Error
Question 4
What will be the output of the following code?
import numpy as np
arr = np.array([1, 2, 3, 4])
arr = arr.astype(float)
print(arr)
[1 2 3 4]
[1.0 2.0 3.0 4.0]
[1. 2. 3. 4. ]
Error
Question 5
What will be the output of this code?
import numpy as np
arr = np.array([[1, 2], [3, 4]])
print(arr.shape)
(2, 2)
(1, 4)
(4, )
(2, 1)
Question 6
Which of the following will create a 3x3 matrix filled with zeros?
np.zeros(3, 3)
np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])
np.zeros((3, 3))
np.zeros([3, 3])
Question 7
What will be the output of the following code?
import numpy as np
arr = np.array([1, 2, 3, 4])
print(np.ndim(arr))
1
4
None
2
Question 8
Which method is used to create an array of equally spaced values?
np.linspace()
np.arrange()
np.array()
np.arrange()
Question 9
What will be the output of the following code?
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(np.sum(arr))
15
10
5
1
Question 10
What is the correct way to create a 4x4 identity matrix in NumPy?
np.eye(4)
np.array([1, 0, 0, 0], [0, 1, 0, 0],[0, 0, 1, 0], [1, 0, 0, 1]]
np.identity(4)
Both a and b
There are 10 questions to complete.