本文介绍了如何将向量归一化/非归一化到范围 [-1;1]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何标准化一个向量到范围[-1;1]

我想使用函数norm,因为它会更快.

I would like to use function norm, because it will be faster.

还请告诉我如何在规范化之后去规范化该向量?

Also let me know how I can denormalize that vector after normalization?

推荐答案

norm 标准化一个向量,使其平方和为 1.

norm normalizes a vector so that its sum of squares are 1.

如果要对向量进行归一化,使其所有元素都在 0 和 1 之间,则需要使用最小值和最大值,然后可以再次使用它们进行非归一化.

If you want to normalize the vector so that all its elements are between 0 and 1, you need to use the minimum and maximum value, which you can then use to denormalize again.

%# generate some vector
vec = randn(10,1);

%# get max and min
maxVec = max(vec);
minVec = min(vec);

%# normalize to -1...1
vecN = ((vec-minVec)./(maxVec-minVec) - 0.5 ) *2;

%# to "de-normalize", apply the calculations in reverse
vecD = (vecN./2+0.5) * (maxVec-minVec) + minVec

这篇关于如何将向量归一化/非归一化到范围 [-1;1]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-15 12:52