Python Forum
Computing the distance between each pair of points
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Computing the distance between each pair of points
#1
X = rand.rand(10, 2)
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn; seaborn.set() # Plot styling
plt.scatter(X[:, 0], X[:, 1], s=100);
dist_sq = np.sum((X[:, np.newaxis, :] - X[np.newaxis, :, :]) ** 2, axis=-1)
what I don't undersand is this part:
differences = X[:, np.newaxis, :] - X[np.newaxis, :, :]
what's happening between these two brackets, these two colons. Help is appreciated.
Reply


Messages In This Thread
Computing the distance between each pair of points - by Truman - Jun-09-2020, 09:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Cloud computing advice needed sawtooth500 3 605 Apr-18-2024, 09:23 PM
Last Post: sawtooth500
  How to most effectively unpack list of name-value pair dictionaries in a dataframe? zlim 1 797 Nov-07-2023, 10:56 PM
Last Post: zlim
  Could anyone help me get the jaccard distance between my dataframes please? :) a_real_phoenix 0 1,831 Jun-27-2019, 06:01 PM
Last Post: a_real_phoenix
  Converting days to years in loop while computing values across grid cells Lightning1800 2 2,728 May-15-2018, 08:44 PM
Last Post: Lightning1800
  Error in computing FFT operation raady07 1 4,405 Jan-18-2017, 08:30 AM
Last Post: j.crater

Forum Jump:

User Panel Messages

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