Python Forum
How can I make a faster search algorithm
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I make a faster search algorithm
#10
Hi

Interesting topic (briefly read I confess); let me doing some remarks:
- if you're dealing with numbers (0 and 1 typically), then you can use numpy and vectorization to speed-up your code
- it can be combined with "slicing" to get and compare arrays/vectors
- have a look to numpy.array_equal to compare 2 arrays/vectors (never tested so far but I can imagine the size of the vector is not an issue),

If you cannot avoid loops, have a look to Numba library (http://numba.pydata.org)

Finally, interesting benchmarking has been done by the Nasa to compare C, Python, Julia languages among others, and C is much faster than Python
(type "Basic Comparison of Python, Julia, Matlab, IDL and Java (2018 Edition)" + Nasa on Google); it's also interesting to note than vectorization is very powerfull

Paul

n = 1000000;
vect1 = np.random.randint(2,size = n);
vect2 = np.copy(vect1);
identical = np.array_equiv(vect1,vect2);

## now I change 1 value to 2
chang = np.random.randint(n, size = 1);
vect2[chang] = 2;
identical2 = np.array_equiv(vect1,vect2);

extract_part = vect2[100 : 350];

[python]PUT CODE HERE
Reply


Messages In This Thread
RE: How can I make a faster search algorithm - by paul18fr - Apr-15-2019, 11:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Basic binary search algorithm - using a while loop Drone4four 1 460 Jan-22-2024, 06:34 PM
Last Post: deanhystad
  Writing a Linear Search algorithm - malformed string representation Drone4four 10 1,157 Jan-10-2024, 08:39 AM
Last Post: gulshan212
  go over and search in numpy array faster caro 7 1,908 Jun-20-2022, 04:54 PM
Last Post: deanhystad
  Trying to search and make new column from the keyword. dgarg 1 1,526 Dec-20-2021, 08:41 PM
Last Post: deanhystad
  Search faster? Pedroski55 1 2,009 Dec-06-2020, 10:03 PM
Last Post: Larz60+
  how to make iterative search more efficient renergy 2 2,314 Jan-03-2020, 03:43 PM
Last Post: stullis
  To make an algorithm work faster pianistseb 3 2,866 Apr-01-2019, 08:42 AM
Last Post: Gribouillis
  How can I make this function faster? Brennan 10 6,345 Jun-29-2018, 08:33 PM
Last Post: ichabod801
  How do I make this code run faster? DontHurtMe 0 2,469 Nov-04-2017, 12:12 PM
Last Post: DontHurtMe

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020