Python Programming - Arrays

Exercise : Arrays - General Questions
  • Arrays - General Questions
26.
In NumPy, how do you find the indices of elements that satisfy a given condition in an array?
np.index_of(arr, condition)
np.where(condition, arr)
np.find_indices(arr, condition)
np.where(condition)
Answer: Option
Explanation:
The np.where() function in NumPy returns the indices of elements that satisfy a given condition.

27.
How do you perform element-wise multiplication of two NumPy arrays, arr1 and arr2?
np.multiply(arr1, arr2)
arr1 * arr2
arr1.mul(arr2)
np.product(arr1, arr2)
Answer: Option
Explanation:
The * operator can be used for element-wise multiplication of two NumPy arrays.

28.
What does the NumPy function numpy.eye(N, M=None, k=0) do?
Creates an identity matrix with dimensions N x N.
Generates a random matrix of size N x M.
Reshapes an array to have dimensions N x M.
Computes the eigenvalues of a matrix.
Answer: Option
Explanation:
The numpy.eye() function creates an identity matrix with dimensions N x N.

29.
How do you perform element-wise addition of a scalar value, 5, to a NumPy array arr?
np.add_scalar(arr, 5)
arr.add(5)
arr + 5
np.scalar_add(arr, 5)
Answer: Option
Explanation:
The + operator can be used for element-wise addition of a scalar value to a NumPy array.

30.
What is the purpose of the NumPy function numpy.flip(arr, axis=None)?
Rotates the array elements.
Reverses the order of elements along a specified axis.
Shifts the elements to the left.
Computes the cumulative sum of array elements.
Answer: Option
Explanation:
The numpy.flip() function reverses the order of elements along a specified axis.