Python Programming - Arrays

Exercise : Arrays - General Questions
  • Arrays - General Questions
76.
Given a NumPy array arr = np.array([[1, 2], [3, 4], [5, 6]]), what does arr.flatten(order='F') do?
Flattens the array in C-style order (row-wise).
Flattens the array in Fortran-style order (column-wise).
Creates a new array by transposing the original array.
Reshapes the array to have a single row.
Answer: Option
Explanation:
The flatten() function with order='F' flattens the array in Fortran-style order.

77.
What does the NumPy function numpy.linspace(1, 10, 5) return?
[1, 3, 5, 7, 10]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[1.0, 3.25, 5.5, 7.75, 10.0]
[1, 2.25, 3.5, 4.75, 6]
Answer: Option
Explanation:
The numpy.linspace() function generates evenly spaced numbers over a specified range.

78.
How can you concatenate two NumPy arrays arr1 and arr2 along the second axis?
np.concatenate((arr1, arr2), axis=1)
np.concat(arr1, arr2, axis=1)
np.merge(arr1, arr2, axis=1)
np.append(arr1, arr2, axis=1)
Answer: Option
Explanation:
The np.concatenate() function can be used to concatenate arrays along a specified axis.

79.
What does the expression np.eye(4, k=1) generate?
4x4 identity matrix with ones below the main diagonal.
4x4 identity matrix with ones above the main diagonal.
4x4 identity matrix with ones on the main diagonal.
4x4 identity matrix with zeros below the main diagonal.
Answer: Option
Explanation:
The np.eye() function generates an identity matrix with ones on the main diagonal, and the k parameter shifts the diagonal.

80.
How can you calculate the element-wise product of two NumPy arrays arr1 and arr2?
np.multiply(arr1, arr2)
arr1 * arr2
np.product(arr1, arr2)
np.prod(arr1, arr2)
Answer: Option
Explanation:
The * operator performs element-wise multiplication of two arrays.