Python Programming - Arrays
Exercise : Arrays - General Questions
- Arrays - General Questions
56.
How can you check if all elements in a NumPy array
arr
are non-zero?
Answer: Option
Explanation:
The code
np.all(arr != 0)
checks if all elements in the array are non-zero.
57.
What does the NumPy function
numpy.diag([1, 2, 3])
do?
Answer: Option
Explanation:
The
numpy.diag()
function creates a diagonal matrix with the specified values on the main diagonal.
58.
Given a NumPy array
arr = np.array([5, 2, 8, 1, 7])
, what does np.argmax(arr)
return?Answer: Option
Explanation:
The
np.argmax()
function returns the index of the maximum value in the array.
59.
What is the purpose of the NumPy function
numpy.concatenate((arr1, arr2), axis=0)
?
Answer: Option
Explanation:
The
numpy.concatenate()
function joins the arrays along the specified axis, in this case, along the rows.
60.
How can you extract the diagonal elements from a NumPy array
arr
?
Answer: Option
Explanation:
The
np.diagonal()
function extracts the diagonal elements from the array.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers