Python Programming - Arrays

Exercise : Arrays - General Questions
  • Arrays - General Questions
31.
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)
['odd' 'even' 'odd' 'even' 'odd']
['even' 'odd' 'even' 'odd' 'even']
[False True False True False]
[1 0 1 0 1]
Answer: Option
Explanation:
The code uses np.where() to label even and odd numbers in the array.

32.
In NumPy, what does the function numpy.mean(arr, axis=None) compute?
Median of the array.
Sum of the array elements.
Mean (average) of the array values along the specified axis.
Standard deviation of the array.
Answer: Option
Explanation:
The numpy.mean() function computes the mean (average) of the array values along the specified axis.

33.
What does the NumPy function numpy.diag(arr, k=0) do?
Computes the determinant of the array.
Extracts the diagonal elements from the array.
Transposes the array.
Finds the eigenvalues of the array.
Answer: Option
Explanation:
The numpy.diag() function extracts the diagonal elements from the array.

34.
What is the purpose of the NumPy function numpy.outer(arr1, arr2)?
Computes the outer product of two arrays.
Concatenates two arrays along a specified axis.
Transposes the array.
Reshapes the array.
Answer: Option
Explanation:
The numpy.outer() function computes the outer product of two arrays.

35.
Given a NumPy array arr = np.array([3, 1, 4, 1, 5, 9]), what does the code arr[::-1] do?
Reverses the order of elements in the array.
Selects only the even-indexed elements.
Creates a new array with the same elements.
Removes the last element from the array.
Answer: Option
Explanation:
The code arr[::-1] reverses the order of elements in the array.