Sorting and Searching in Array

Last Updated :
Discuss
Comments

Question 1

Which function in NumPy is used to sort an array?

  • np.sort()

  • np.order()

  • np.arrange()

  • np.sorted()

Question 2

What will be the output of the following code?

Python
import numpy as np
arr = np.array([3, 1, 4, 1, 5])
print(np.sort(arr))


  • [3, 1, 4, 1, 5]

  • [1, 1, 3, 4, 5]

  • Error

  • [5, 4, 3, 1, 1]

Question 3

Which of the following functions sorts an array in-place?

  • np.sort()

  • np.argsort()

  • np.ndarray.sort()

  • np.sorted()

Question 4

What does the np.argsort() function return?

  • A sorted array

  • Indices that would sort the array

  • A boolean array indicating sorted positions

  • The sum of indices

Question 5

What will be the output of the following code?

Python
import numpy as np
arr = np.array([30, 10, 20])
print(np.argsort(arr))


  • [0, 1, 2]

  • [1, 2, 0]

  • [2, 1, 0]

  • Error

Question 6

What will be the output of this code?

Python
import numpy as np
arr = np.array([[8, 5, 6], [3, 7, 2]])
print(np.sort(arr, axis=1))


  • [[5, 6, 8]

    [2, 3, 7]]

  • [[8, 5, 6]

    [3, 7, 2]]

  • [[2, 3, 7]

    [5, 6, 8]]

  • [[5, 6, 8]

    [2, 3, 7]]

Question 7

Which function would you use to find the index of the first occurrence of a specific value in an array?

  • np.searchsorted()

  • np.where()

  • np.find()

  • np.index()

Question 8

What will np.searchsorted() return for the code below?

Python
import numpy as np
arr = np.array([1, 3, 4, 6])
print(np.searchsorted(arr, 5))


  • 2

  • 3

  • 4

  • Error

Question 9

What will np.searchsorted() return for the code below?

Python
import numpy as np
arr = np.array([1, 3, 4, 6])
print(np.searchsorted(arr, 5))


  • 2

  • 3

  • 4

  • Error

Question 10

What will be the output of this code?

Python
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(np.searchsorted(arr, [0, 3, 6]))


  • [0, 2, 5]

  • Error

  • [0, 3, 6]

  • [1, 3, 4]

Tags:

There are 11 questions to complete.

Take a part in the ongoing discussion