为什么 numpy.std() 使用 abs()?
Why does numpy.std() use abs()?
我查看了numpy库,在numpy
中找到了标准差的定义如下:
std = sqrt(mean(abs(x - x.mean())**2))
为什么要使用abs()
函数? - 因为根据数学定义,数字的平方将为正数。
所以我想:
abs(x - x.mean())**2 == (x - x.mean())**2
实数的平方总是正数,但复数则不然。
一个非常简单的例子:j**2=-1
一个更复杂的(双关语)示例:(3-2j)**2=(5-12j)
来自文档:
Note that, for complex numbers, std
takes the absolute value before squaring, so that the result is always real and nonnegative.
注意:
Python 使用 j
作为虚数单位,而数学家使用 i
.
我查看了numpy库,在numpy
中找到了标准差的定义如下:
std = sqrt(mean(abs(x - x.mean())**2))
为什么要使用abs()
函数? - 因为根据数学定义,数字的平方将为正数。
所以我想:
abs(x - x.mean())**2 == (x - x.mean())**2
实数的平方总是正数,但复数则不然。
一个非常简单的例子:j**2=-1
一个更复杂的(双关语)示例:(3-2j)**2=(5-12j)
来自文档:
Note that, for complex numbers,
std
takes the absolute value before squaring, so that the result is always real and nonnegative.
注意:
Python 使用 j
作为虚数单位,而数学家使用 i
.