Python Programming - Arrays

Exercise : Arrays - General Questions
  • Arrays - General Questions
16.
What does the array.extend(iterable) method do?
Appends the entire array to another array.
Adds elements from an iterable to the end of the array.
Inserts elements from an iterable at a specific index.
Raises a TypeError.
Answer: Option
Explanation:
The extend() method in the array module adds elements from an iterable to the end of the array.

17.
How do you find the index of the maximum value in a NumPy array named arr?
np.max_index(arr)
np.argmax(arr)
arr.index(max(arr))
arr.find_max_index()
Answer: Option
Explanation:
The argmax() function in NumPy returns the indices of the maximum value in an array.

18.
What is the purpose of the numpy.linspace(start, stop, num) function?
Creates a list of integers from start to stop.
Generates a NumPy array with evenly spaced values from start to stop.
Computes the logarithm of each element in the array.
Rounds the elements of the array to the nearest integer.
Answer: Option
Explanation:
The numpy.linspace() function generates a NumPy array with evenly spaced values over a specified range.

19.
Which of the following methods is used to reshape a NumPy array?
arr.rearrange(new_shape)
arr.reshape(new_shape)
numpy.resize(arr, new_shape)
numpy.rearrange(arr, new_shape)
Answer: Option
Explanation:
The reshape() method in NumPy is used to change the shape of an array.

20.
In NumPy, what does the function numpy.mean() do?
Computes the median of the array.
Calculates the sum of the array elements.
Finds the mode of the array.
Computes the mean (average) of the array values.
Answer: Option
Explanation:
The numpy.mean() function calculates the mean (average) of the array values.