Python Forum
'Get closest value array in array of arrays.' follow up help.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'Get closest value array in array of arrays.' follow up help.
#11
(Dec-04-2019, 11:43 PM)scidam Wrote:
(Dec-04-2019, 04:03 PM)DreamingInsanity Wrote: this could be improved using numpy right?
Yes, Numpy version of your function find_closest should work faster.

def find_closest(x, array2d):
    return array2d[np.argmin(np.abs(array2d.sum(axis=1) - x.sum()))]
Thanks for that! I will definitely go the numpy route in the future.

Thanks everyone!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Metasploit Graph and Append Array Difficulties Tuurbo46 37 761 May-21-2026, 09:31 AM
Last Post: Dustbunny
Big Grin [solved] how to associate value in an array? paul18fr 9 3,780 Aug-26-2025, 05:44 AM
Last Post: paul18fr
  Numpy, array(2d,bool), flipping regions. MvGulik 2 1,633 Oct-27-2024, 11:06 AM
Last Post: MvGulik
  JSON File - extract only the data in a nested array for CSV file shwfgd 2 2,252 Aug-26-2024, 10:14 PM
Last Post: shwfgd
  ValueError: could not broadcast input array from shape makingwithheld 1 5,659 Jul-06-2024, 03:02 PM
Last Post: paul18fr
  python code to calculate mean of an array of numbers using numpy viren 3 2,126 May-29-2024, 04:49 PM
Last Post: Gribouillis
  Writing a cycle to find the nearest point from the array Tysrusko 0 1,321 May-10-2024, 11:49 AM
Last Post: Tysrusko
  Elegant way to apply each element of an array to a dataframe? sawtooth500 7 4,883 Mar-29-2024, 05:51 PM
Last Post: deanhystad
  Concatenate array for 3D plotting armanditod 1 1,908 Mar-21-2024, 08:08 PM
Last Post: deanhystad
  Convert numpy array to image without loading it into RAM. DreamingInsanity 7 13,057 Feb-08-2024, 09:38 AM
Last Post: paul18fr

Forum Jump:

User Panel Messages

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