Python Programming - Arrays

Exercise : Arrays - General Questions
  • Arrays - General Questions
36.
How do you check if all elements in a NumPy array arr are non-zero?
np.check_nonzero(arr)
np.nonzero(arr)
np.all_nonzero(arr)
np.all(arr != 0)
Answer: Option
Explanation:
The code np.all(arr != 0) checks if all elements in the array are non-zero.

37.
What does the NumPy function numpy.concatenate((arr1, arr2), axis=0) do?
Joins the arrays along the specified axis.
Adds the arrays element-wise.
Multiplies the arrays element-wise.
Computes the cross product of the arrays.
Answer: Option
Explanation:
The numpy.concatenate() function joins the arrays along the specified axis.

38.
How can you reshape a NumPy array arr into a 2x3 matrix?
arr.reshape(2, 3)
arr.resize(2, 3)
np.reshape(arr, (2, 3))
np.resize(arr, (2, 3))
Answer: Option
Explanation:
The arr.reshape(2, 3) method reshapes the array into a 2x3 matrix.

39.
Given two NumPy arrays arr1 and arr2, what does np.column_stack((arr1, arr2)) do?
Stacks the arrays vertically.
Stacks the arrays horizontally.
Creates a new array by vertically concatenating the arrays.
Creates a new array by horizontally concatenating the arrays.
Answer: Option
Explanation:
The np.column_stack() function stacks the arrays horizontally.

40.
What does the NumPy function numpy.unique(arr) return?
The array with only unique elements.
The count of unique elements in the array.
The indices of unique elements in the array.
The mean of unique elements in the array.
Answer: Option
Explanation:
The numpy.unique() function returns the array with only unique elements.