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
  Elegant way to apply each element of an array to a dataframe? sawtooth500 7 376 Mar-29-2024, 05:51 PM
Last Post: deanhystad
  Concatenate array for 3D plotting armanditod 1 250 Mar-21-2024, 08:08 PM
Last Post: deanhystad
  Convert numpy array to image without loading it into RAM. DreamingInsanity 7 5,861 Feb-08-2024, 09:38 AM
Last Post: paul18fr
  How Write Part of a Binary Array? Assembler 1 338 Jan-14-2024, 11:35 PM
Last Post: Gribouillis
  Loop over an an array of array Chendipeter 1 570 Nov-28-2023, 06:37 PM
Last Post: deanhystad
  How to remove some elements from an array in python? gohanhango 9 1,133 Nov-28-2023, 08:35 AM
Last Post: Gribouillis
  IPython errors for numpy array min/max methods muelaner 1 552 Nov-04-2023, 09:22 PM
Last Post: snippsat
  Convert np Array A to networkx G IanAnderson 2 673 Jul-05-2023, 11:42 AM
Last Post: IanAnderson
  Help using a dynamic array excel formula with XLWings FXMonkey 2 1,274 Jun-06-2023, 09:46 PM
Last Post: FXMonkey
  [Newbie] Multiple Array azhuda 3 1,011 Jun-01-2023, 04:29 AM
Last Post: azhuda

Forum Jump:

User Panel Messages

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