
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Calculating Euclidean distance using SciPy
Euclidean distance is the distance between two real-valued vectors. Mostly we use it to calculate the distance between two rows of data having numerical values (floating or integer values). Below is the formula to calculate Euclidean distance −
$$\mathrm{d(r,s) =\sqrt{\sum_{i=1}^{n}(s_i-r_i)^2} }$$
Here,
r and s are the two points in Euclidean n-space.
si and ri are Euclidean vectors.
n denotes the n-space.
Let’s see how we can calculate Euclidean distance between two points using SciPy library −
Example
# Importing the SciPy library from scipy.spatial import distance # Defining the points A = (1, 2, 3, 4, 5, 6) B = (7, 8, 9, 10, 11, 12) A, B # Computing the Euclidean distance euclidean_distance = distance.euclidean(A, B) print('Euclidean Distance b/w', A, 'and', B, 'is: ', euclidean_distance)
Output
((1, 2, 3, 4, 5, 6), (7, 8, 9, 10, 11, 12)) Euclidean Distance b/w (1, 2, 3, 4, 5, 6) and (7, 8, 9, 10, 11, 12) is: 1 4.696938456699069
- Related Questions & Answers
- Calculating the Manhattan distance using SciPy
- Calculating the Hamming distance using SciPy
- Calculating the Minkowski distance using SciPy
- Euclidean Algorithm for calculating GCD in JavaScript
- C Program for Basic Euclidean algorithms?
- C Program for Extended Euclidean algorithms?
- Python Program for Basic Euclidean algorithms
- Python Program for Extended Euclidean algorithms
- C++ Program to Implement Extended Euclidean Algorithm
- Finding determinant of a square matrix using SciPy library
- Finding inverse of a square matrix using SciPy library
- How to solve banded matrix equations using Python SciPy?
- How to solve triangular matrix equations using Python SciPy?
- How to solve Toeplitz matrix equation using Python SciPy?
- Find HCF of two numbers without using recursion or Euclidean algorithm in C++
Advertisements