Re: Creating a Listable Function
- To: mathgroup at smc.vnet.net
- Subject: [mg73583] Re: Creating a Listable Function
- From: "Ray Koopman" <koopman at sfu.ca>
- Date: Thu, 22 Feb 2007 04:36:53 -0500 (EST)
- References: <ergqjm$j0v$1@smc.vnet.net>
On Feb 20, 10:59 pm, Gregory Lypny <gregory.ly... at videotron.ca> wrote:
> Hello everyone,
>
> I've created a function for population variance, which does not make
> use of Mathematica's built-in Variance function.
>
> VarPop[x_] := Total[(x - Mean@x)^2]/Length@x
>
> How do I need to change the definition to have the function operate
> across lists much like Total, Mean, and Variance do?
>
> Regards,
>
> Greg
If you want your function to handle arrays the way Mean and Variance
do then I think you need a two-step definition:
vp[x_?VectorQ] := #.#&[x-Mean@x]/Length@x
vp[x_?ArrayQ] := Map[vp, Transpose[x, RotateRight @ Range @
ArrayDepth @ x], {-2}]