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)
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?
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?
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)?
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?
Answer: Option
Explanation:
The code
arr[::-1] reverses the order of elements in the array.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers