Exercise: Python

Questions for: Arrays

What is the purpose of the NumPy function numpy.concatenate((arr1, arr2), axis=0)?
A:
Joins the arrays along the columns.
B:
Joins the arrays along the rows.
C:
Creates a new array with the maximum values from both arrays.
D:
Computes the dot product of the arrays.
Answer: B
The numpy.concatenate() function joins the arrays along the specified axis, in this case, along the rows.
Given a NumPy array arr = np.array([5, 2, 8, 1, 7]), what does np.argmax(arr) return?
A:
1
B:
2
C:
4
D:
0
Answer: B
The np.argmax() function returns the index of the maximum value in the array.
What does the NumPy function numpy.diag([1, 2, 3]) do?
A:
Creates a 3x3 array with values 1, 2, and 3 on the main diagonal.
B:
Generates a diagonal matrix with values 1, 2, and 3.
C:
Reshapes an existing array to have dimensions 1x3.
D:
Computes the determinant of a 3x3 matrix.
Answer: B
The numpy.diag() function creates a diagonal matrix with the specified values on the main diagonal.
How can you check if all elements in a NumPy array arr are non-zero?
A:
np.nonzero(arr)
B:
np.all(arr != 0)
C:
arr.all_nonzero()
D:
arr.is_nonzero()
Answer: B
The code np.all(arr != 0) checks if all elements in the array are non-zero.
What does the NumPy function numpy.flip(arr, axis=1) do?
A:
Flips the array vertically.
B:
Flips the array horizontally.
C:
Flips the array along both axes.
D:
Flips the array along the specified axis.
Answer: B
The numpy.flip() function flips the array horizontally along the specified axis.
Ad Slot (Above Pagination)
Quiz