Exercise: Python

Questions for: Arrays

What is the purpose of the NumPy function numpy.outer(arr1, arr2)?
A:
Computes the outer product of two arrays.
B:
Concatenates two arrays along a specified axis.
C:
Transposes the array.
D:
Reshapes the array.
Answer: A
The numpy.outer() function computes the outer product of two arrays.
What does the NumPy function numpy.diag(arr, k=0) do?
A:
Computes the determinant of the array.
B:
Extracts the diagonal elements from the array.
C:
Transposes the array.
D:
Finds the eigenvalues of the array.
Answer: B
The numpy.diag() function extracts the diagonal elements from the array.
In NumPy, what does the function numpy.mean(arr, axis=None) compute?
A:
Median of the array.
B:
Sum of the array elements.
C:
Mean (average) of the array values along the specified axis.
D:
Standard deviation of the array.
Answer: C
The numpy.mean() function computes the mean (average) of the array values along the specified axis.
What is the output of the following NumPy code snippet?
import numpy as np

arr = np.array([1, 2, 3, 4, 5])
result = np.where(arr % 2 == 0, "even", "odd")
print(result)
A:
['odd' 'even' 'odd' 'even' 'odd']
B:
['even' 'odd' 'even' 'odd' 'even']
C:
[False True False True False]
D:
[1 0 1 0 1]
Answer: A
The code uses np.where() to label even and odd numbers in the array.
What is the purpose of the NumPy function numpy.flip(arr, axis=None)?
A:
Rotates the array elements.
B:
Reverses the order of elements along a specified axis.
C:
Shifts the elements to the left.
D:
Computes the cumulative sum of array elements.
Answer: B
The numpy.flip() function reverses the order of elements along a specified axis.
Ad Slot (Above Pagination)
Quiz