python 矩阵化求点和点集每个元素的欧式距离

参考matlab:

%............................................
function [D]=dist(i,x)

% function: [D]=dist(i,x)
%
% Aim: 
% Calculates the Euclidean distances between i and all objects in x	 
%								    
% Input: 
% i - an object (1,n)
% x - data matrix (m,n); m-objects, n-variables	    
%                                                                 
% Output: 
% D - Euclidean distance (m,1)


[m,n]=size(x);
D=sqrt(sum((((ones(m,1)*i)-x).^2)'));

if n==1
   D=abs((ones(m,1)*i-x))';
end

python

H_str,W_str = colorbar.shape[:2]

data = np.sqrt( np.sum( np.square( (np.ones((H_str, 1), np.int64) * temp) - colorbar), axis=1) ).T

 

最新回复(0)
/jishuidLPfhMxPXf0U5P5Rtan_2FTlv6JvZPpHlXLymNBf3TGo_3D4795337
8 简首页