Java 规范化数组是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23642694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 00:28:59  来源:igfitidea点击:

What does it mean to normalize an array?

javaarraysnormalize

提问by Lucas Alanis

I need to normalize an array that contains values between 0 to 1024 into an array that will contain values between 0-255. I am doing this in Java but I am wanting to understand what exactly does it mean to "normalize an array" rather than asking for exact code.

我需要将包含 0 到 1024 之间的值的数组标准化为一个包含 0 到 255 之间的值的数组。我正在用 Java 执行此操作,但我想了解“规范化数组”而不是要求确切的代码究竟意味着什么。

采纳答案by peter.petrov

To normalize a vector in math means to divide each of its elements
to some value V so that the length/norm of the resulting vector is 1.
Turns out the needed V is equal the length (the length of the vector).

在数学中对向量进行归一化意味着将其每个元素除以
某个值 V,以便结果向量的长度/范数为 1。
结果所需的 V 等于长度(向量的长度)。

Say you have this array.

假设你有这个数组。

[-3, +4]

[-3, +4]

Its length (in Euclid metric) is: V = sqrt((-3)^2 + (+4)^2) = 5

它的长度(以欧几里德度量)是: V = sqrt((-3)^2 + (+4)^2) = 5

So its corresponding normalized vector is:

所以其对应的归一化向量为:

[-3/5, +4/5]

[-3/5, +4/5]

Its length is now: sqrt ( (-3/5)^2 + (+4/5)^2 )which is 1.

它的长度现在是:sqrt ( (-3/5)^2 + (+4/5)^2 )1。

You can use another metric (e.g. I think Manhattan distance)
but the idea is the same. Divide each element of your array
by Vwhere V = || your_vector || = norm (your_vector).

您可以使用另一个指标(例如我认为曼哈顿距离),
但想法是相同的。将数组
的每个元素除以Vwhere V = || your_vector || = norm (your_vector)

So I think this is what is meant here.

所以我认为这就是这里的意思。

See also:

也可以看看:

http://www.fundza.com/vectors/normalize/

http://www.fundza.com/vectors/normalize/

http://mathworld.wolfram.com/NormalizedVector.html

http://mathworld.wolfram.com/NormalizedVector.html

回答by Cliff Ribaudo

Normalize in this case essentially means to convert the value in your original scale to a value on a different scale. Something like this will do it:

在这种情况下,归一化本质上意味着将原始比例中的值转换为不同比例的值。像这样的事情会做到:

x = origVal / 1024;
xNorm = 255 * x;

You will have to decide how you want to handle rounding.

您必须决定如何处理舍入。

So for example:

例如:

.5 = 512 / 1024;
127.5 = 255 * .5;