标准化向量? [英] Normalize a vector?

查看:87
本文介绍了标准化向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何归一化一个 M*N 向量,使其所有元素的总和现在等于 1.我在网上浏览了一点,似乎没有什么与我需要的完全匹配.谢谢!

How do you normalize a M*N vector, such that the sum of all its elements is now equal to 1. I browsed online a little, and nothing seems to quite match what I need. Thanks!

推荐答案

您将所有元素相加,然后将每个元素除以总和.

You add up all the elements, then divide each element by the sum.

显然,除法(至少)需要是浮点数.由于这表示一个浮点矩阵,因此在保持最大精度的同时进行求和将非常重要.

Obviously, the division (at least) needs to be in floating point. Since that indicates a floating point matrix, doing the summing while maintaining maximum accuracy will be non-trivial.

举个例子,如果你有一个大元素和很多小元素,你可能会通过将所有小元素加在一起得到更准确的结果,然后将总和添加到大元素,而不是将每个小元素单独添加到大元素中.

Just for example, if you have one large element, and a lot of small elements, you'll probably get a more accurate result from adding all the small elements together, then adding that sum to the large element, than if you added each small element to the large one individually.

我想我应该补充一点,处理这个问题的常用方法称为 Kahan 求和,以数值分析的高级大师 William Kahan 的名字命名.

I suppose I should add that the usual way to deal with this is called Kahan summation, after the high guru of numerical analysis, William Kahan.

这篇关于标准化向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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