相似度计算方法-曼哈顿距离 (Manhattan Distance)

定义

        曼哈顿距离(Manhattan distance),也称为城市街区距离或L1距离,是一种度量两个点之间距离的方法,它是指在网格状的环境中两点之间沿着坐标轴方向移动的总距离。这种距离度量方式特别适用于只能沿水平和垂直方向移动的情况。

        公式:d= \sum\limits_{i=1}\limits^{n}|x_i - y_i|

代码实现

public class ManhattanDistance {

    public static void main(String[] args) {
        double[] point1 = {1.0, 2.0};
        double[] point2 = {4.0, 6.0};

        double distance = calculateManhattanDistance(point1, point2);
        System.out.printf("The Manhattan distance between the points is: %.2f\n", distance);
    }

    /**
     * 计算两个点之间的曼哈顿距离。
     *
     * @param point1 第一个点的坐标数组
     * @param point2 第二个点的坐标数组
     * @return 两个点之间的曼哈顿距离
     */
    public static double calculateManhattanDistance(double[] point1, doubl
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值