NumPy Searching and Sorting Arrays

Machine Learning courses with 100+ Real-time projects Start Now!!

Program 1

# Searching and Sorting in Numpy
import numpy as np
# Sorting 
# ar1=np.array([5,2,6,1,3,4,8,10,9])
# ar1=np.sort(ar1)
# print(ar1)
# ar1=np.array([[2,5,3],[1,6,5],[7,4,5],[9,5,3]])
# ar1=np.sort(ar1,axis=0)
# print(ar1)

ar1=np.array([5,2,6,1,3,4,8,10,9])
ar1=np.sort(ar1)
print(ar1)
x=np.searchsorted(ar1,6)
print(x)















# Searching
# ar=np.array([1,2,3,5,6,7,9,12])
# print(ar)
# m=np.searchsorted(ar,[2,6,12])
# print(m)

# ar=np.array([1,3,5,7,9,10,5,9,5,23,5,66])
#     #              0 1 2 3 4  5  6 7 8  9  10 11 
# newar=np.where(ar==39)
# # print(newar)
# # print(np.size(newar))
# if(np.size(newar)>0):
#     print("Searhing success")
# else:
#     print("Searhing not success")

 

We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *