JavaScript isn't enabled in your browser, so this file can't be opened. Enable and reload.
Python Quiz on NumPy Sorting Array
There are
20 questions based on NumPy Sorting Array .
Sign in to Google
to save your progress.
Learn more
* Indicates required question
Q1. What is the output of the following code?
import numpy as np
arr = np.array([3, 1, 2])
print(np.sort(arr))
*
4 points
[3, 2, 1]
[1, 2, 3]
[2, 3, 1]
[1, 3, 2]
Q2. What will be printed?
arr = np.array([4, 2, 9])
arr.sort()
print(arr)
*
4 points
[2, 4, 9]
[9, 4, 2]
[4, 2, 9]
Error
Q3. What is the output of this code?
arr = np.array([[3, 2, 1], [6, 5, 4]])
print(np.sort(arr))
*
4 points
[[1 2 3], [4 5 6]]
[[3 2 1], [6 5 4]]
[[1 2 3], [6 5 4]]
[[1 2 3], [4 6 5]]
Q4. Which axis will sort the columns of a 2D array?
arr = np.array([[3, 2], [1, 4]])
print(np.sort(arr, axis=0))
*
4 points
axis=1
axis=-1
axis=0
axis=2
Q5. What does np.argsort() return?
arr = np.array([30, 10, 20])
print(np.argsort(arr))
*
4 points
[30, 10, 20]
Option 2
[2, 0, 1]
[1, 2, 0]
Q6. What is the effect of [::-1] on a sorted array?
arr = np.array([4, 1, 3])
print(np.sort(arr)[::-1])
*
4 points
[4, 3, 1]
[1, 3, 4]
[3, 1, 4]
[4, 1, 3]
Q7. What does this return?
arr = np.array([[7, 8], [1, 3]])
print(np.sort(arr, axis=None))
*
4 points
[[1, 3], [7, 8]]
[1, 3, 7, 8]
[[7, 8], [1, 3]]
Error
Q8. How do you sort a NumPy array in descending order?
arr = np.array([5, 2, 9])
print(np.sort(arr)[::-1])
*
4 points
[2, 5, 9]
[5, 2, 9]
[9, 5, 2]
[9, 2, 5]
Q9. What is the result of sorting along axis=1?
arr = np.array([[3, 2, 1], [6, 5, 4]])
print(np.sort(arr, axis=1))
*
4 points
[[1 2 3], [4 5 6]]
[[3 2 1], [6 5 4]]
[[1 2 3], [6 5 4]]
[[1 2 3], [4 6 5]]
Q10. What does this output?
arr = np.array(['banana', 'apple', 'cherry'])
print(np.sort(arr))
*
4 points
['cherry', 'banana', 'apple']
['apple', 'banana', 'cherry']
['banana', 'cherry', 'apple']
['apple', 'cherry', 'banana']
Q11. Which method is used to return the indices that would sort an array?
arr = np.array([3, 1, 2])
print(np.argsort(arr))
*
4 points
[3, 1, 2]
[1, 2, 0]
[2, 0, 1]
[1, 2, 1]
Q12. What does this return?
arr = np.array([[3, 2], [1, 4]])
print(np.sort(arr, axis=1))
*
4 points
[[3, 2], [4, 1]]
[[2, 3], [1, 4]]
[[2, 3], [4, 1]]
[[1, 4], [2, 3]]
Q13. Can NumPy sort strings?
arr = np.array(['cat', 'dog', 'apple'])
print(np.sort(arr))
*
4 points
['dog', 'cat', 'apple']
['apple', 'cat', 'dog']
Error
['cat', 'dog', 'apple']
Q14. Sorting a boolean array:
arr = np.array([True, False, True])
print(np.sort(arr))
*
4 points
[True, True, False]
[1, 0, 1]
[True, False, True]
[False, True, True]
Q15. What is the sorted version of this 2D array?
arr = np.array([[5, 2], [3, 8]])
print(np.sort(arr, axis=0))
*
4 points
[[5, 2], [3, 8]]
[[3, 2], [5, 8]]
[[2, 5], [3, 8]]
[[2, 3], [5, 8]]
Q16. What is the output of this code?
import numpy as np
arr = np.array([[9, 3], [1, 5]])
print(np.sort(arr, axis=1))
*
4 points
[[3, 9], [1, 5]]
[[9, 3], [5, 1]]
[[1, 5], [3, 9]]
[[1, 3], [5, 9]]
Q17. What is the output of argsort() here?
arr = np.array([40, 10, 20])
print(np.argsort(arr))
*
4 points
[0, 1, 2]
[1, 2, 0]
[2, 0, 1]
[2, 1, 0]
Q18. What will be printed?
arr = np.array([True, False, True])
print(np.sort(arr)[::-1])
*
4 points
[True, True, False]
[False, True, True]
[True, False, True]
[1, 0, 1]
Q19. What does this output?
arr = np.array([[5, 3], [2, 4]])
print(np.argsort(arr, axis=0))
*
4 points
[[1, 1], [0, 0]]
[[1, 0], [0, 1]]
[[0, 1], [1, 0]]
[[1, 0], [1, 1]]
Q20. What is the output?
arr = np.array([[4, 1], [2, 3]])
print(np.argsort(arr, axis=1))
*
4 points
[[1, 0], [0, 1]]
[[0, 1], [1, 0]]
[[1, 0], [1, 0]]
[[0, 1], [0, 1]]
Submit
Clear form
Forms
This content is neither created nor endorsed by Google.
Report Abuse
Terms of Service
Privacy Policy
Help and feedback
Contact form owner
Help Forms improve
Report