Exercise: Python

Questions for: Arrays

What does the NumPy function numpy.linspace(1, 10, 5) do?
A:
Creates an array with values ranging from 1 to 10 with a step of 5.
B:
Generates a sequence of 5 evenly spaced values between 1 and 10.
C:
Reshapes an existing array to have dimensions 1x10.
D:
Computes the logarithm of each element in the array.
Answer: B
The numpy.linspace() function generates a sequence of 5 evenly spaced values between 1 and 10.
How can you find the indices of non-zero elements in a NumPy array arr?
A:
np.where(arr != 0)
B:
np.nonzero(arr)
C:
np.find_nonzero(arr)
D:
arr.index_nonzero()
Answer: B
The np.nonzero() function returns the indices of non-zero elements in the array.
What does the NumPy function numpy.zeros((3, 4)) do?
A:
Creates a 3x4 array with all elements initialized to zero.
B:
Generates an array with random values.
C:
Reshapes an existing array to have dimensions 3x4.
D:
Computes the square root of each element in the array.
Answer: A
The numpy.zeros() function creates a 3x4 array with all elements initialized to zero.
How do you find the median value of a NumPy array arr?
A:
np.median(arr)
B:
arr.median()
C:
np.mean(arr)
D:
arr.mean()
Answer: A
The np.median() function calculates the median value of the array.
What does the NumPy function numpy.unique(arr) return?
A:
The array with only unique elements.
B:
The count of unique elements in the array.
C:
The indices of unique elements in the array.
D:
The mean of unique elements in the array.
Answer: A
The numpy.unique() function returns the array with only unique elements.
Ad Slot (Above Pagination)
Quiz