Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 euclidean distance jenya56 Programmer named Tim Posts: 18 Threads: 8 Joined: Jun 2018 Reputation: 0 Likes received: 0 #1 Mar-29-2019, 01:09 AM Dear all, I have two 2D arrays (size nxm) and I want to calculate the Euclidean distance between them. Meaning that the distance will be a single number whereas my arrays are nxm. Is there a quick way to do it besides going into double loop? Thank you! Jenya scidam Posts: 671 Threads: 1 Joined: Mar 2018 Reputation: 90 Likes received: 103 #2 Mar-29-2019, 02:08 AM You can use SciPy library, look at cdist function. jenya56 Programmer named Tim Posts: 18 Threads: 8 Joined: Jun 2018 Reputation: 0 Likes received: 0 #3 Mar-29-2019, 02:45 AM Does cdist return a single number? Because I thought it would return a matrix? Thank you! scidam Posts: 671 Threads: 1 Joined: Mar 2018 Reputation: 90 Likes received: 103 #4 Mar-29-2019, 02:56 AM Yes, it returns a matrix. Look at the following minimal example: ```from scipy.spatial.distance import cdist import numpy as np np.random.seed(10) X = np.random.rand(3, 10) Y = np.random.rand(4, 10) cdist(X, Y) `````````Output:array([[1.00025041, 1.11616128, 1.49867252, 1.33747696], [1.76040012, 1.26928995, 1.4958863 , 1.31219674], [1.21858991, 1.08164983, 1.0274891 , 1.11686588]]) `````` « Next Oldest | Next Newest »

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)