Exercise: Python

Questions for: Arrays

How do you stack two NumPy arrays vertically?
A:
np.concatenate((arr1, arr2), axis=0)
B:
np.vstack((arr1, arr2))
C:
np.stack((arr1, arr2), axis=0)
D:
np.append(arr1, arr2, axis=0)
Answer: B
The np.vstack() function in NumPy is used to stack arrays vertically.
What does the function numpy.zeros_like(arr) do in NumPy?
A:
Creates a new array with zeros of the same shape as arr.
B:
Fills the existing array arr with zeros.
C:
Checks if all elements in arr are zero.
D:
Reshapes arr to have all zero elements.
Answer: A
The numpy.zeros_like() function creates a new array with zeros of the same shape as the input array arr.
Which NumPy function is used to find the unique elements of an array?
A:
numpy.unique()
B:
numpy.distinct()
C:
arr.unique()
D:
numpy.find_unique()
Answer: A
The numpy.unique() function is used to find the unique elements of an array.
What is the purpose of the numpy.concatenate() function in NumPy?
A:
Concatenates two Python lists.
B:
Combines two NumPy arrays along a specified axis.
C:
Merges two dictionaries.
D:
Joins two strings.
Answer: B
The numpy.concatenate() function in NumPy is used to concatenate two arrays along a specified axis.
In NumPy, what does the function numpy.mean() do?
A:
Computes the median of the array.
B:
Calculates the sum of the array elements.
C:
Finds the mode of the array.
D:
Computes the mean (average) of the array values.
Answer: D
The numpy.mean() function calculates the mean (average) of the array values.
Ad Slot (Above Pagination)
Quiz