Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Creating a Listable Function

  • To: mathgroup at
  • Subject: [mg73583] Re: Creating a Listable Function
  • From: "Ray Koopman" <koopman at>
  • Date: Thu, 22 Feb 2007 04:36:53 -0500 (EST)
  • References: <ergqjm$j0v$>

On Feb 20, 10:59 pm, Gregory Lypny < at> 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}]

  • Prev by Date: Roman Numerals
  • Next by Date: Re: Find index of maximal element in multi-dimensional array
  • Previous by thread: Re: Re: Creating a Listable Function
  • Next by thread: Re: Creating a Listable Function