How to compute distance for a matrix and a vector?

  distance, numpy, python

In python, given one matrix of size 3*2 like
A=[[x11,x12,x13],[x21,x22,x23]] and a column vector b=[mu1;mu2]. If I want to compute the Euclidean distance between each column of A and vector b. For example, for the first column, the distance ‘d1` is given by

A=[[x11,x12,x13],[x21,x22,x23]]
b=[[mu1],[mu2]]
d1=(x11-mu1)^2+(x21-mu2)^2
#second column
d2=(x12-mu1)^2+(x22-mu2)^2
# so on

So the distance can be scored in a matrix [d1,d2,d3] of size 3*1:

I can compute the distance for a smaller matrix. But if matrix A is larger like size 100*2, how to get all number of distances (i.e. a matrix of size 100*1 easily?

Source: Python Questions

LEAVE A COMMENT