Exercise: Python

Questions for: Arrays

Which of the following methods is used to reshape a NumPy array?
A:
arr.rearrange(new_shape)
B:
arr.reshape(new_shape)
C:
numpy.resize(arr, new_shape)
D:
numpy.rearrange(arr, new_shape)
Answer: B
The reshape() method in NumPy is used to change the shape of an array.
What is the purpose of the numpy.linspace(start, stop, num) function?
A:
Creates a list of integers from start to stop.
B:
Generates a NumPy array with evenly spaced values from start to stop.
C:
Computes the logarithm of each element in the array.
D:
Rounds the elements of the array to the nearest integer.
Answer: B
The numpy.linspace() function generates a NumPy array with evenly spaced values over a specified range.
How do you find the index of the maximum value in a NumPy array named arr?
A:
np.max_index(arr)
B:
np.argmax(arr)
C:
arr.index(max(arr))
D:
arr.find_max_index()
Answer: B
The argmax() function in NumPy returns the indices of the maximum value in an array.
What does the array.extend(iterable) method do?
A:
Appends the entire array to another array.
B:
Adds elements from an iterable to the end of the array.
C:
Inserts elements from an iterable at a specific index.
D:
Raises a TypeError.
Answer: B
The extend() method in the array module adds elements from an iterable to the end of the array.
What is the purpose of the array.remove(element) method in the array module?
A:
Removes the first occurrence of the specified element from the array.
B:
Removes all occurrences of the specified element from the array.
C:
Removes the element at the specified index.
D:
Raises a ValueError.
Answer: A
The remove() method in the array module removes the first occurrence of the specified element from the array.
Ad Slot (Above Pagination)
Quiz