Python Forum
finding the closest floating point number in a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
finding the closest floating point number in a list
#13
At least you can become familiar with what the most used Python's modules are used for and what they are capable. That way when you start a project you will know that there are alternative/different way to do something and you can do deeper research about it. And eventually, use it. Numpy is fast. Really fast.

I don't know NumPy and I have never used it but because of this topic, I google it just a bit to make an example. I just know that it's fast. So here is how much.

In [1]: import math

In [2]: nums = list(range(2, 100001))

In [3]: def power_it(numbers):
   ...:     return [math.pow(num, 5) for num in numbers]
   ...:

In [4]: %timeit power_it(nums)
22.6 ms ± 2.65 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)

In [5]: import numpy as np

In [6]: def np_pow(numbers):
   ...:     return np.power(numbers, 5)
   ...:

In [7]: %timeit np_pow(nums)
4.89 ms ± 14.9 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [8]: l = np.array(nums)

In [9]: %timeit np_pow(l)
258 µs ± 1.39 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
I have to thank you for that because I'm planning to use it constantly now. I am surpriced Sick
Consider I have opened two browsers Chrome and Firefox with 118 and 499 tabs. ;)
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
RE: finding the closest floating point number in a list - by wavic - Sep-16-2019, 11:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error is finding mean of a list PythonBoy 4 947 Sep-11-2023, 02:38 PM
Last Post: PythonBoy
  Delete strings from a list to create a new only number list Dvdscot 8 1,584 May-01-2023, 09:06 PM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,285 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  Finding combinations of list of items (30 or so) LynnS 1 894 Jan-25-2023, 02:57 PM
Last Post: deanhystad
  Finding the price based on industry and number of transactions chandramouliarun 0 924 Jul-26-2022, 07:36 PM
Last Post: chandramouliarun
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 4,929 Jul-01-2022, 01:23 PM
Last Post: deanhystad
Question Finding string in list item jesse68 8 1,922 Jun-30-2022, 08:27 AM
Last Post: Gribouillis
  Split a number to list and list sum must be number sunny9495 5 2,338 Apr-28-2022, 09:32 AM
Last Post: Dexty
  Divide a number by numbers in a list. Wallen 7 8,098 Feb-12-2022, 01:51 PM
Last Post: deanhystad
  finding point in m grid jenya56 0 836 Feb-06-2022, 09:00 PM
Last Post: jenya56

Forum Jump:

User Panel Messages

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