矩阵与向量之间的欧式距离 [英] Euclidean distance between matrix and vector

查看:323
本文介绍了矩阵与向量之间的欧式距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从另一个向量的每一列计算一个向量的欧几里得. 这是正确的吗?

Calculate the euclidean of a vector from each column of another vector. Is this correct?

distances=np.sqrt(np.sum(np.square(new_v-val.reshape(10,1)),axis=0))

new_v是一个矩阵. val.reshape(10,1)是列向量. 另一种/更好的方法.

new_v is a matrix. val.reshape(10,1) is a column vector. Another other/better ways to do it.

推荐答案

您所拥有的是正确的. numpy.linalg中有一个更简单的方法:

What you have is correct. There is a simpler method available in numpy.linalg:

from numpy.linalg import norm
norm(new_v.T-val, axis=1, ord=2)

这篇关于矩阵与向量之间的欧式距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆