Why Python 3?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sun Apr 20 22:13:56 EDT 2014
On Sun, 20 Apr 2014 14:40:38 -0700, Roy Smith wrote:
> In article <mailman.9383.1398012417.18130.python-list at python.org>,
> Chris Angelico <rosuav at gmail.com> wrote:
>
>> On Mon, Apr 21, 2014 at 2:22 AM, Ian Kelly <ian.g.kelly at gmail.com>
>> wrote:
>> > When I'm writing a generic average function, I probably don't know
>> > whether it will ever be used to average complex numbers.
>>
>> This keeps coming up in these discussions. How often do you really
>> write a function that generic? And if you do, isn't it doing something
>> so simple that it's then the caller's responsibility (not the
>> function's, and not the language's) to ensure that it gets the right
>> result?
>>
>> ChrisA
>
> Hmmm. Taking the average of a set of complex numbers has a reasonable
> physical meaning. But, once you start down that path, I'm not sure how
> far you can go before things no long make sense. What's the standard
> deviation of a set of complex numbers? Does that even have any meaning?
Yes it does. Stdev is a measure of scale of the distribution, and is
always real and non-negative. For complex values, you can calculate it
using:
(abs(x - mean))**2
which is how numpy does it, or from the complex conjugate:
x1 = x-mean
x1.conj()*x1
which is how Matlab does it.
http://docs.scipy.org/doc/numpy/reference/generated/numpy.std.html
http://www.mathworks.com.au/matlabcentral/newsreader/view_thread/57323
Hence the variance is always non-negative, and the standard deviation is
always real. See also:
https://en.wikipedia.org/wiki/Variance#Generalizations
--
Steven D'Aprano
http://import-that.dreamwidth.org/
More information about the Python-list
mailing list