Standardize the Samples (Compute the z-Score)












14














Given a list of floating point numbers, standardize it.



Details




  • A list $x_1,x_2,ldots,x_n$ is standardized if the mean of all values is 0, and the standard deviation is 1. One way to compute this is by first computing the mean $mu$ and the standard deviation $sigma$ as
    $$ mu = frac1nsum_{i=1}^n x_i qquad sigma = sqrt{frac{1}{n}sum_{i=1}^n (x_i -mu)^2} ,$$
    and then computing the standardization by replacing every $x_i$ with $frac{x_i-mu}{sigma}$.

  • You can assume that the input contains at least two distinct entries (which implies $sigma neq 0$).

  • Note that some implementations use the sample standard deviation, which is not equal to the population standard deviation $sigma$ we are using here.

  • There is a CW answer for all trivial solutions.


Examples



[1,2,3] -> [-1.224744871391589,0.0,1.224744871391589]
[1,2] -> [-1,1]
[-3,1,4,1,5] -> [-1.6428571428571428,-0.21428571428571433,0.8571428571428572,-0.21428571428571433,1.2142857142857144]


(These examples have been generated with this script.)












share|improve this question





























    14














    Given a list of floating point numbers, standardize it.



    Details




    • A list $x_1,x_2,ldots,x_n$ is standardized if the mean of all values is 0, and the standard deviation is 1. One way to compute this is by first computing the mean $mu$ and the standard deviation $sigma$ as
      $$ mu = frac1nsum_{i=1}^n x_i qquad sigma = sqrt{frac{1}{n}sum_{i=1}^n (x_i -mu)^2} ,$$
      and then computing the standardization by replacing every $x_i$ with $frac{x_i-mu}{sigma}$.

    • You can assume that the input contains at least two distinct entries (which implies $sigma neq 0$).

    • Note that some implementations use the sample standard deviation, which is not equal to the population standard deviation $sigma$ we are using here.

    • There is a CW answer for all trivial solutions.


    Examples



    [1,2,3] -> [-1.224744871391589,0.0,1.224744871391589]
    [1,2] -> [-1,1]
    [-3,1,4,1,5] -> [-1.6428571428571428,-0.21428571428571433,0.8571428571428572,-0.21428571428571433,1.2142857142857144]


    (These examples have been generated with this script.)












    share|improve this question



























      14












      14








      14


      1





      Given a list of floating point numbers, standardize it.



      Details




      • A list $x_1,x_2,ldots,x_n$ is standardized if the mean of all values is 0, and the standard deviation is 1. One way to compute this is by first computing the mean $mu$ and the standard deviation $sigma$ as
        $$ mu = frac1nsum_{i=1}^n x_i qquad sigma = sqrt{frac{1}{n}sum_{i=1}^n (x_i -mu)^2} ,$$
        and then computing the standardization by replacing every $x_i$ with $frac{x_i-mu}{sigma}$.

      • You can assume that the input contains at least two distinct entries (which implies $sigma neq 0$).

      • Note that some implementations use the sample standard deviation, which is not equal to the population standard deviation $sigma$ we are using here.

      • There is a CW answer for all trivial solutions.


      Examples



      [1,2,3] -> [-1.224744871391589,0.0,1.224744871391589]
      [1,2] -> [-1,1]
      [-3,1,4,1,5] -> [-1.6428571428571428,-0.21428571428571433,0.8571428571428572,-0.21428571428571433,1.2142857142857144]


      (These examples have been generated with this script.)












      share|improve this question















      Given a list of floating point numbers, standardize it.



      Details




      • A list $x_1,x_2,ldots,x_n$ is standardized if the mean of all values is 0, and the standard deviation is 1. One way to compute this is by first computing the mean $mu$ and the standard deviation $sigma$ as
        $$ mu = frac1nsum_{i=1}^n x_i qquad sigma = sqrt{frac{1}{n}sum_{i=1}^n (x_i -mu)^2} ,$$
        and then computing the standardization by replacing every $x_i$ with $frac{x_i-mu}{sigma}$.

      • You can assume that the input contains at least two distinct entries (which implies $sigma neq 0$).

      • Note that some implementations use the sample standard deviation, which is not equal to the population standard deviation $sigma$ we are using here.

      • There is a CW answer for all trivial solutions.


      Examples



      [1,2,3] -> [-1.224744871391589,0.0,1.224744871391589]
      [1,2] -> [-1,1]
      [-3,1,4,1,5] -> [-1.6428571428571428,-0.21428571428571433,0.8571428571428572,-0.21428571428571433,1.2142857142857144]


      (These examples have been generated with this script.)









      code-golf math array-manipulation arithmetic statistics






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 14 '18 at 18:43







      flawr

















      asked Dec 14 '18 at 18:37









      flawrflawr

      26.6k665188




      26.6k665188






















          25 Answers
          25






          active

          oldest

          votes


















          7















          R, 51 45 38 37 bytes



          Thanks to Giuseppe and J.Doe!



          function(x)scale(x)/(1-1/sum(x|1))^.5


          Try it online!






          share|improve this answer























          • Beat me by 2 bytes and 1 minute
            – Sumner18
            Dec 14 '18 at 19:38



















          5














          CW for all trivial entries






          Python 3 + scipy, 31 bytes





          from scipy.stats import*
          zscore


          Try it online!



          Octave / MATLAB, 15 bytes





          @(x)zscore(x,1)


          Try it online!






          share|improve this answer































            5















            APL (Dyalog Classic), 21 20 19 bytes





            (-÷.5*⍨⊢÷⌹×≢)+/-⊢×≢


            Try it online!



            ⊢÷⌹ is sum of squares



            ⊢÷⌹×≢ is sum of squares divided by length






            share|improve this answer























            • Wow. I shouldn't be surprised anymore, but I am every time
              – Quintec
              Dec 16 '18 at 16:19



















            4















            MATL, 10 bytes



            tYm-t&1Zs/


            Try it online!



            Explanation



            t       % Implicit input
            % Duplicate
            Ym % Mean
            - % Subtract, element-wise
            t % Duplicate
            &1Zs % Standard deviation using normalization by n
            / % Divide, element-wise
            % Implicit display





            share|improve this answer































              4














              APL+WIN, 41,32 30 bytes



              9 bytes saved thanks to Erik + 2 more thanks to ngn



              x←v-(+/v)÷⍴v←⎕⋄x÷(+/x×x÷⍴v)*.5


              Prompts for vector of numbers and calculates mean standard deviation and standardised elements of input vector






              share|improve this answer























              • Can't you assign x←v-(+/v)÷⍴v←⎕ and then do x÷((+/x*2)÷⍴v)*.5?
                – Erik the Outgolfer
                Dec 14 '18 at 19:11










              • I can indeed. Thanks.
                – Graham
                Dec 14 '18 at 19:24










              • does apl+win do singleton extension (1 2 3+,4 ←→ 1 2 3+4)? if yes, you could rewrite (+/x*2)÷⍴v as +/x×x÷⍴v
                – ngn
                Dec 16 '18 at 10:24










              • @ngn That works for another 2 bytes. Thanks.
                – Graham
                Dec 16 '18 at 12:47



















              3















              R + pryr, 53 52 bytes



              -1 byte using sum(x|1) instead of length(x) as seen in @Robert S.'s solution





              pryr::f((x-(y<-mean(x)))/(sum((x-y)^2)/sum(x|1))^.5)


              For being a language built for statisticians, I'm amazed that this doesn't have a built-in function. At least not one that I could find. Even the function mosaic::zscore doesn't yield the expected results. This is likely due to using the population standard deviation instead of sample standard deviation.



              Try it online!






              share|improve this answer



















              • 2




                You can change the <- into a = to save 1 byte.
                – Robert S.
                Dec 14 '18 at 19:52










              • @J.Doe nope, I used the method I commented on Robert S.'s solution. scale is neat!
                – Giuseppe
                Dec 14 '18 at 19:57






              • 2




                @J.Doe since you only use n once you can use it directly for 38 bytes
                – Giuseppe
                Dec 14 '18 at 20:00








              • 2




                @RobertS. here on PPCG we tend to encourage allowing flexible input and output, including outputting more than is required, with the exception of challenges where the precise layout of the output is the whole point of the challenge.
                – ngm
                Dec 14 '18 at 21:09






              • 6




                Of course R built-ins wouldn't use "population variance". Only confused engineers would use such a thing (hencethe Python and Matlab answers ;))
                – ngm
                Dec 14 '18 at 21:12



















              3















              Tcl, 126 bytes



              proc S L {lmap c $L {expr ($c-[set m ([join $L +])/[set n [llength $L]].])/sqrt(([join [lmap c $L {expr ($c-$m)**2}] +])/$n)}}


              Try it online!






              share|improve this answer































                2















                Jelly, 10 bytes



                _ÆmµL½÷ÆḊ×


                Try it online!



                It's not any shorter, but Jelly's determinant function ÆḊ also calculates vector norm.



                _Æm             x - mean(x)
                µ then:
                L½ Square root of the Length
                ÷ÆḊ divided by the norm
                × Multiply by that value





                share|improve this answer





















                • Hey, nice alternative! Unfortunately, I can't see a way to shorten it.
                  – Erik the Outgolfer
                  Dec 14 '18 at 22:34



















                2














                Mathematica, 25 bytes



                Mean[(a=#-Mean@#)a]^-.5a&


                Pure function. Takes a list of numbers as input and returns a list of machine-precision numbers as output. Note that the built-in Standardize function uses the sample variance by default.






                share|improve this answer





























                  2















                  J, 22 bytes



                  -1 byte thanks to Cows quack!



                  (-%[:%:1#.-*-%#@[)+/%#


                  Try it online!




                  J, 31 23 bytes



                  (-%[:%:#@[%~1#.-*-)+/%#


                  Try it online!



                                     +/%# - mean (sum (+/) divided (%) by the number of samples (#)) 
                  ( ) - the list is a left argument here (we have a hook)
                  - - the difference between each sample and the mean
                  * - multiplied by
                  - - the difference between each sample and the mean
                  1#. - sum by base-1 conversion
                  %~ - divided by
                  #@[ - the length of the samples list
                  %: - square root
                  [: - convert to a fork (function composition)
                  - - subtract the mean from each sample
                  % - and divide it by sigma





                  share|improve this answer



















                  • 1




                    Rearranging it gives 22 [:(%[:%:1#.*:%#)]-+/%# tio.run/##y/qfVmyrp2CgYKVg8D/…, I think one of those caps could be removed, but haven't had any luck so far, EDIT: a more direct byteshaving is (-%[:%:1#.-*-%#@[)+/%# also at 22
                    – Cows quack
                    Dec 15 '18 at 13:12












                  • @Cows quack Thanks!
                    – Galen Ivanov
                    Dec 15 '18 at 14:30



















                  2















                  APL (Dyalog Unicode), 33 29 bytes





                  {d÷.5*⍨l÷⍨+/×⍨d←⍵-(+/⍵)÷l←≢⍵}


                  -4 bytes thanks to @ngn



                  Try it online!






                  share|improve this answer























                  • you could assign ⍵-m to a variable and remove m← like this: {d÷.5*⍨l÷⍨+/×⍨d←⍵-(+/⍵)÷l←≢⍵}
                    – ngn
                    Dec 16 '18 at 10:39










                  • @ngn Ah, nice, thanks, I didn't see that duplication somehow
                    – Quintec
                    Dec 16 '18 at 16:15



















                  2














                  Haskell, 80 75 68 bytes



                  t x=k(/sqrt(f$sum$k(^2)))where k g=g.(-f(sum x)+)<$>x;f=(/sum(1<$x))


                  Thanks to @flawr for the suggestions to use sum(1<$x) instead of sum[1|_<-x] and to inline the mean, @xnor for inlining the standard deviation and other reductions.



                  Expanded:



                  -- Standardize a list of values of any floating-point type.
                  standardize :: Floating a => [a] -> [a]
                  standardize input = eachLessMean (/ sqrt (overLength (sum (eachLessMean (^2)))))
                  where

                  -- Map a function over each element of the input, less the mean.
                  eachLessMean f = map (f . subtract (overLength (sum input))) input

                  -- Divide a value by the length of the input.
                  overLength n = n / sum (map (const 1) input)





                  share|improve this answer



















                  • 1




                    You can replace [1|_<-x] with (1<$x) to save a few bytes. That is a great trick for avoiding the fromIntegral, that I haven't seen so far!
                    – flawr
                    Dec 16 '18 at 10:54












                  • By the way: I like using tryitonline, you can run your code there and then copy the preformatted aswer for posting here!
                    – flawr
                    Dec 16 '18 at 10:57










                  • And you do not have to define m.
                    – flawr
                    Dec 16 '18 at 11:02












                  • You can write (-x+) for (+(-x)) to avoid parens. Also it looks like f can be pointfree: f=(/sum(1<$x)), and s can be replaced with its definition.
                    – xnor
                    Dec 16 '18 at 20:00












                  • @xnor Ooh, (-x+) is handy, I’m sure I’ll be using that in the future
                    – Jon Purdy
                    Dec 16 '18 at 21:15



















                  2















                  MathGolf, 7 bytes



                  ▓-_²▓√/


                  Try it online!



                  Explanation



                  This is literally a byte-for-byte recreation of Kevin Cruijssen's 05AB1E answer, but I save some bytes from MathGolf having 1-byters for everything needed for this challenge. Also the answer looks quite good in my opinion!



                  ▓         get average of list
                  - pop a, b : push(a-b)
                  _ duplicate TOS
                  ² pop a : push(a*a)
                  ▓ get average of list
                  √ pop a : push(sqrt(a)), split string to list
                  / pop a, b : push(a/b), split strings





                  share|improve this answer





























                    1














                    JavaScript (ES7),  80  79 bytes





                    a=>a.map(x=>(x-g(a))/g(a.map(x=>(x-m)**2))**.5,g=a=>m=eval(a.join`+`)/a.length)


                    Try it online!



                    Commented



                    a =>                      // given the input array a
                    a.map(x => // for each value x in a:
                    (x - g(a)) / // compute (x - mean(a)) divided by
                    g( // the standard deviation:
                    a.map(x => // for each value x in a:
                    (x - m) ** 2 // compute (x - mean(a))²
                    ) // compute the mean of this array
                    ) ** .5, // and take the square root
                    g = a => // g = helper function taking an array a,
                    m = eval(a.join`+`) // computing the mean
                    / a.length // and storing the result in m
                    ) // end of outer map()





                    share|improve this answer































                      1















                      Python 3 + numpy, 46 bytes





                      lambda a:(a-mean(a))/std(a)
                      from numpy import*


                      Try it online!






                      share|improve this answer































                        1















                        Haskell, 59 bytes





                        (%)i=sum.map(^i)
                        f l=[(0%l*y-1%l)/sqrt(2%l*0%l-1%l^2)|y<-l]


                        Try it online!



                        Doesn't use libraries.



                        The helper function % computes the sum of ith powers of a list, which lets us get three useful values.





                        • 0%l is the length of l (call this n)


                        • 1%l is the sum of l (call this s)


                        • 2%l is the sum of squares of l (call this m)


                        We can express the z-score of an element y as



                        (n*y-s)/sqrt(n*v-s^2)


                        (This is the expression (y-s/n)/sqrt(v/n-(s/n)^2) simplified a bit by multiplying the top and bottom by n.)



                        We can insert the expressions 0%l, 1%l, 2%l without parens because the % we define has higher precedence than the arithmetic operators.



                        (%)i=sum.map(^i) is the same length as i%l=sum.map(^i)l. Making it more point-free doesn't help. Defining it like g i=... loses bytes when we call it. Although % works for any list but we only call it with the problem input list, there's no byte loss in calling it with argument l every time because a two-argument call i%l is no longer than a one-argument one g i.






                        share|improve this answer





















                        • We do have $LaTeX$ here:)
                          – flawr
                          Dec 16 '18 at 9:59










                        • I really like the % idea! It looks just like the discrete version of the statistical moments.
                          – flawr
                          Dec 16 '18 at 10:02



















                        1















                        K (oK), 33 23 bytes



                        -10 bytes thanks to ngn!



                        {t%%(+/t*t:x-/x%#x)%#x}


                        Try it online!



                        First attempt at coding (I don't dare to name it "golfing") in K. I'm pretty sure it can be done much better (too many variable names here...)






                        share|improve this answer



















                        • 1




                          nice! you can replace the initial (x-m) with t (tio)
                          – ngn
                          Dec 16 '18 at 9:53






                        • 1




                          the inner { } is unnecessary - its implicit parameter name is x and it has been passed an x as argument (tio)
                          – ngn
                          Dec 16 '18 at 9:56








                        • 1




                          another -1 byte by replacing x-+/x with x-/x. the left argument to -/ serves as initial value for the reduction (tio)
                          – ngn
                          Dec 16 '18 at 10:08












                        • @ngn Thank you! Now I see that the first 2 golfs are obvious; the last one is beyond my current level :)
                          – Galen Ivanov
                          Dec 16 '18 at 10:14



















                        1














                        MATLAB, 26 bytes



                        Trivial-ish, std(,1) for using population standard deviation



                        f=@(x)(x-mean(x))/std(x,1)





                        share|improve this answer





























                          1














                          TI-Basic (83 series), 14 11 bytes



                          Ans-mean(Ans
                          Ans/√(mean(Ans²


                          Takes input in Ans. For example, if you type the above into prgmSTANDARD, then {1,2,3}:prgmSTANDARD will return {-1.224744871,0.0,1.224744871}.



                          Previously, I tried using the 1-Var Stats command, which stores the population standard deviation in σx, but it's less trouble to compute it manually.






                          share|improve this answer































                            1















                            05AB1E, 9 bytes



                            ÅA-DnÅAt/


                            Port of @Arnauld's JavaScript answer, so make sure to upvote him!



                            Try it online or verify all test cases.



                            Explanation:





                            ÅA          # Calculate the mean of the (implicit) input
                            # i.e. [-3,1,4,1,5] → 1.6
                            - # Subtract it from each value in the (implicit) input
                            # i.e. [-3,1,4,1,5] and 1.6 → [-4.6,-0.6,2.4,-0.6,3.4]
                            D # Duplicate that list
                            n # Take the square of each
                            # i.e. [-4.6,-0.6,2.4,-0.6,3.4] → [21.16,0.36,5.76,0.36,11.56]
                            ÅA # Pop and calculate the mean of that list
                            # i.e. [21.16,0.36,5.76,0.36,11.56] → 7.84
                            t # Take the square-root of that
                            # i.e. 7.84 → 2.8
                            / # And divide each value in the duplicated list with it (and output implicitly)
                            # i.e. [-4.6,-0.6,2.4,-0.6,3.4] and 2.8 → [-1.6428571428571428,
                            # -0.21428571428571433,0.8571428571428572,-0.21428571428571433,1.2142857142857144]





                            share|improve this answer





























                              0















                              Jelly, 10 bytes



                              _Æm÷²Æm½Ɗ$


                              Try it online!






                              share|improve this answer





























                                0














                                Pyth, 21 19 bytes



                                mc-dJ.OQ@.Om^-Jk2Q2


                                Try it online here.



                                mc-dJ.OQ@.Om^-Jk2Q2Q   Implicit: Q=eval(input())
                                Trailing Q inferred
                                J.OQ Take the average of Q, store the result in J
                                m Q Map the elements of Q, as k, using:
                                -Jk Difference between J and k
                                ^ 2 Square it
                                .O Find the average of the result of the map
                                @ 2 Square root it
                                - this is the standard deviation of Q
                                m Q Map elements of Q, as d, using:
                                -dJ d - J
                                c Float division by the standard deviation
                                Implicit print result of map


                                Edit: after seeing Kevin's answer, changed to use the average builtin for the inner results. Previous answer: mc-dJ.OQ@csm^-Jk2QlQ2






                                share|improve this answer































                                  0















                                  SNOBOL4 (CSNOBOL4), 229 bytes



                                  	DEFINE('Z(A)')
                                  Z X =X + 1
                                  M =M + A<X> :S(Z)
                                  N =X - 1.
                                  M =M / N
                                  D X =GT(X) X - 1 :F(S)
                                  A<X> =A<X> - M :(D)
                                  S X =LT(X,N) X + 1 :F(Y)
                                  S =S + A<X> ^ 2 / N :(S)
                                  Y S =S ^ 0.5
                                  N A<X> =A<X> / S
                                  X =GT(X) X - 1 :S(N)
                                  Z =A :(RETURN)


                                  Try it online!



                                  Link is to a functional version of the code which constructs an array from STDIN given its length and then its elements, then runs the function Z on that, and finally prints out the values.



                                  Defines a function Z which returns an array.



                                  The 1. on line 4 is necessary to do the floating point arithmetic properly.






                                  share|improve this answer





























                                    0















                                    Julia 0.7, 37 bytes





                                    a->(a-mean(a))/std(a,corrected=false)


                                    Try it online!






                                    share|improve this answer





























                                      0















                                      Charcoal, 25 19 bytes



                                      ≧⁻∕ΣθLθθI∕θ₂∕ΣXθ²Lθ


                                      Try it online! Link is to verbose version of code. Explanation:



                                             θ    Input array
                                      ≧ Update each element
                                      ⁻ Subtract
                                      Σ Sum of
                                      θ Input array
                                      ∕ Divided by
                                      L Length of
                                      θ Input array


                                      Calculate $mu$ and vectorised subtract it from each $x_i$.



                                        θ         Updated array
                                      ∕ Vectorised divided by
                                      ₂ Square root of
                                      Σ Sum of
                                      θ Updated array
                                      X Vectorised to power
                                      ² Literal 2
                                      ∕ Divided by
                                      L Length of
                                      θ Array
                                      I Cast to string
                                      Implicitly print each element on its own line.


                                      Calculate $sigma$, vectorised divide each $x_i$ by it, and output the result.



                                      Edit: Saved 6 bytes thanks to @ASCII-only for a) using SquareRoot() instead of Power(0.5) b) fixing vectorised Divide() (it was doing IntDivide() instead) c) making Power() vectorise.






                                      share|improve this answer























                                      • crossed out 25 = no bytes? :P (Also, you haven't updated the TIO link yet)
                                        – ASCII-only
                                        Dec 25 '18 at 10:59












                                      • @ASCII-only Oops, thanks!
                                        – Neil
                                        Dec 25 '18 at 14:32











                                      Your Answer





                                      StackExchange.ifUsing("editor", function () {
                                      return StackExchange.using("mathjaxEditing", function () {
                                      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
                                      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
                                      });
                                      });
                                      }, "mathjax-editing");

                                      StackExchange.ifUsing("editor", function () {
                                      StackExchange.using("externalEditor", function () {
                                      StackExchange.using("snippets", function () {
                                      StackExchange.snippets.init();
                                      });
                                      });
                                      }, "code-snippets");

                                      StackExchange.ready(function() {
                                      var channelOptions = {
                                      tags: "".split(" "),
                                      id: "200"
                                      };
                                      initTagRenderer("".split(" "), "".split(" "), channelOptions);

                                      StackExchange.using("externalEditor", function() {
                                      // Have to fire editor after snippets, if snippets enabled
                                      if (StackExchange.settings.snippets.snippetsEnabled) {
                                      StackExchange.using("snippets", function() {
                                      createEditor();
                                      });
                                      }
                                      else {
                                      createEditor();
                                      }
                                      });

                                      function createEditor() {
                                      StackExchange.prepareEditor({
                                      heartbeatType: 'answer',
                                      autoActivateHeartbeat: false,
                                      convertImagesToLinks: false,
                                      noModals: true,
                                      showLowRepImageUploadWarning: true,
                                      reputationToPostImages: null,
                                      bindNavPrevention: true,
                                      postfix: "",
                                      imageUploader: {
                                      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                                      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                                      allowUrls: true
                                      },
                                      onDemand: true,
                                      discardSelector: ".discard-answer"
                                      ,immediatelyShowMarkdownHelp:true
                                      });


                                      }
                                      });














                                      draft saved

                                      draft discarded


















                                      StackExchange.ready(
                                      function () {
                                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f177601%2fstandardize-the-samples-compute-the-z-score%23new-answer', 'question_page');
                                      }
                                      );

                                      Post as a guest















                                      Required, but never shown

























                                      25 Answers
                                      25






                                      active

                                      oldest

                                      votes








                                      25 Answers
                                      25






                                      active

                                      oldest

                                      votes









                                      active

                                      oldest

                                      votes






                                      active

                                      oldest

                                      votes









                                      7















                                      R, 51 45 38 37 bytes



                                      Thanks to Giuseppe and J.Doe!



                                      function(x)scale(x)/(1-1/sum(x|1))^.5


                                      Try it online!






                                      share|improve this answer























                                      • Beat me by 2 bytes and 1 minute
                                        – Sumner18
                                        Dec 14 '18 at 19:38
















                                      7















                                      R, 51 45 38 37 bytes



                                      Thanks to Giuseppe and J.Doe!



                                      function(x)scale(x)/(1-1/sum(x|1))^.5


                                      Try it online!






                                      share|improve this answer























                                      • Beat me by 2 bytes and 1 minute
                                        – Sumner18
                                        Dec 14 '18 at 19:38














                                      7












                                      7








                                      7







                                      R, 51 45 38 37 bytes



                                      Thanks to Giuseppe and J.Doe!



                                      function(x)scale(x)/(1-1/sum(x|1))^.5


                                      Try it online!






                                      share|improve this answer















                                      R, 51 45 38 37 bytes



                                      Thanks to Giuseppe and J.Doe!



                                      function(x)scale(x)/(1-1/sum(x|1))^.5


                                      Try it online!







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Dec 14 '18 at 22:10

























                                      answered Dec 14 '18 at 19:34









                                      Robert S.Robert S.

                                      691315




                                      691315












                                      • Beat me by 2 bytes and 1 minute
                                        – Sumner18
                                        Dec 14 '18 at 19:38


















                                      • Beat me by 2 bytes and 1 minute
                                        – Sumner18
                                        Dec 14 '18 at 19:38
















                                      Beat me by 2 bytes and 1 minute
                                      – Sumner18
                                      Dec 14 '18 at 19:38




                                      Beat me by 2 bytes and 1 minute
                                      – Sumner18
                                      Dec 14 '18 at 19:38











                                      5














                                      CW for all trivial entries






                                      Python 3 + scipy, 31 bytes





                                      from scipy.stats import*
                                      zscore


                                      Try it online!



                                      Octave / MATLAB, 15 bytes





                                      @(x)zscore(x,1)


                                      Try it online!






                                      share|improve this answer




























                                        5














                                        CW for all trivial entries






                                        Python 3 + scipy, 31 bytes





                                        from scipy.stats import*
                                        zscore


                                        Try it online!



                                        Octave / MATLAB, 15 bytes





                                        @(x)zscore(x,1)


                                        Try it online!






                                        share|improve this answer


























                                          5












                                          5








                                          5






                                          CW for all trivial entries






                                          Python 3 + scipy, 31 bytes





                                          from scipy.stats import*
                                          zscore


                                          Try it online!



                                          Octave / MATLAB, 15 bytes





                                          @(x)zscore(x,1)


                                          Try it online!






                                          share|improve this answer














                                          CW for all trivial entries






                                          Python 3 + scipy, 31 bytes





                                          from scipy.stats import*
                                          zscore


                                          Try it online!



                                          Octave / MATLAB, 15 bytes





                                          @(x)zscore(x,1)


                                          Try it online!







                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited Dec 14 '18 at 19:37


























                                          community wiki





                                          3 revs, 3 users 58%
                                          flawr
























                                              5















                                              APL (Dyalog Classic), 21 20 19 bytes





                                              (-÷.5*⍨⊢÷⌹×≢)+/-⊢×≢


                                              Try it online!



                                              ⊢÷⌹ is sum of squares



                                              ⊢÷⌹×≢ is sum of squares divided by length






                                              share|improve this answer























                                              • Wow. I shouldn't be surprised anymore, but I am every time
                                                – Quintec
                                                Dec 16 '18 at 16:19
















                                              5















                                              APL (Dyalog Classic), 21 20 19 bytes





                                              (-÷.5*⍨⊢÷⌹×≢)+/-⊢×≢


                                              Try it online!



                                              ⊢÷⌹ is sum of squares



                                              ⊢÷⌹×≢ is sum of squares divided by length






                                              share|improve this answer























                                              • Wow. I shouldn't be surprised anymore, but I am every time
                                                – Quintec
                                                Dec 16 '18 at 16:19














                                              5












                                              5








                                              5







                                              APL (Dyalog Classic), 21 20 19 bytes





                                              (-÷.5*⍨⊢÷⌹×≢)+/-⊢×≢


                                              Try it online!



                                              ⊢÷⌹ is sum of squares



                                              ⊢÷⌹×≢ is sum of squares divided by length






                                              share|improve this answer















                                              APL (Dyalog Classic), 21 20 19 bytes





                                              (-÷.5*⍨⊢÷⌹×≢)+/-⊢×≢


                                              Try it online!



                                              ⊢÷⌹ is sum of squares



                                              ⊢÷⌹×≢ is sum of squares divided by length







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Dec 16 '18 at 12:04

























                                              answered Dec 16 '18 at 10:46









                                              ngnngn

                                              6,94112559




                                              6,94112559












                                              • Wow. I shouldn't be surprised anymore, but I am every time
                                                – Quintec
                                                Dec 16 '18 at 16:19


















                                              • Wow. I shouldn't be surprised anymore, but I am every time
                                                – Quintec
                                                Dec 16 '18 at 16:19
















                                              Wow. I shouldn't be surprised anymore, but I am every time
                                              – Quintec
                                              Dec 16 '18 at 16:19




                                              Wow. I shouldn't be surprised anymore, but I am every time
                                              – Quintec
                                              Dec 16 '18 at 16:19











                                              4















                                              MATL, 10 bytes



                                              tYm-t&1Zs/


                                              Try it online!



                                              Explanation



                                              t       % Implicit input
                                              % Duplicate
                                              Ym % Mean
                                              - % Subtract, element-wise
                                              t % Duplicate
                                              &1Zs % Standard deviation using normalization by n
                                              / % Divide, element-wise
                                              % Implicit display





                                              share|improve this answer




























                                                4















                                                MATL, 10 bytes



                                                tYm-t&1Zs/


                                                Try it online!



                                                Explanation



                                                t       % Implicit input
                                                % Duplicate
                                                Ym % Mean
                                                - % Subtract, element-wise
                                                t % Duplicate
                                                &1Zs % Standard deviation using normalization by n
                                                / % Divide, element-wise
                                                % Implicit display





                                                share|improve this answer


























                                                  4












                                                  4








                                                  4







                                                  MATL, 10 bytes



                                                  tYm-t&1Zs/


                                                  Try it online!



                                                  Explanation



                                                  t       % Implicit input
                                                  % Duplicate
                                                  Ym % Mean
                                                  - % Subtract, element-wise
                                                  t % Duplicate
                                                  &1Zs % Standard deviation using normalization by n
                                                  / % Divide, element-wise
                                                  % Implicit display





                                                  share|improve this answer















                                                  MATL, 10 bytes



                                                  tYm-t&1Zs/


                                                  Try it online!



                                                  Explanation



                                                  t       % Implicit input
                                                  % Duplicate
                                                  Ym % Mean
                                                  - % Subtract, element-wise
                                                  t % Duplicate
                                                  &1Zs % Standard deviation using normalization by n
                                                  / % Divide, element-wise
                                                  % Implicit display






                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited Dec 14 '18 at 19:43

























                                                  answered Dec 14 '18 at 19:33









                                                  Luis MendoLuis Mendo

                                                  74k886291




                                                  74k886291























                                                      4














                                                      APL+WIN, 41,32 30 bytes



                                                      9 bytes saved thanks to Erik + 2 more thanks to ngn



                                                      x←v-(+/v)÷⍴v←⎕⋄x÷(+/x×x÷⍴v)*.5


                                                      Prompts for vector of numbers and calculates mean standard deviation and standardised elements of input vector






                                                      share|improve this answer























                                                      • Can't you assign x←v-(+/v)÷⍴v←⎕ and then do x÷((+/x*2)÷⍴v)*.5?
                                                        – Erik the Outgolfer
                                                        Dec 14 '18 at 19:11










                                                      • I can indeed. Thanks.
                                                        – Graham
                                                        Dec 14 '18 at 19:24










                                                      • does apl+win do singleton extension (1 2 3+,4 ←→ 1 2 3+4)? if yes, you could rewrite (+/x*2)÷⍴v as +/x×x÷⍴v
                                                        – ngn
                                                        Dec 16 '18 at 10:24










                                                      • @ngn That works for another 2 bytes. Thanks.
                                                        – Graham
                                                        Dec 16 '18 at 12:47
















                                                      4














                                                      APL+WIN, 41,32 30 bytes



                                                      9 bytes saved thanks to Erik + 2 more thanks to ngn



                                                      x←v-(+/v)÷⍴v←⎕⋄x÷(+/x×x÷⍴v)*.5


                                                      Prompts for vector of numbers and calculates mean standard deviation and standardised elements of input vector






                                                      share|improve this answer























                                                      • Can't you assign x←v-(+/v)÷⍴v←⎕ and then do x÷((+/x*2)÷⍴v)*.5?
                                                        – Erik the Outgolfer
                                                        Dec 14 '18 at 19:11










                                                      • I can indeed. Thanks.
                                                        – Graham
                                                        Dec 14 '18 at 19:24










                                                      • does apl+win do singleton extension (1 2 3+,4 ←→ 1 2 3+4)? if yes, you could rewrite (+/x*2)÷⍴v as +/x×x÷⍴v
                                                        – ngn
                                                        Dec 16 '18 at 10:24










                                                      • @ngn That works for another 2 bytes. Thanks.
                                                        – Graham
                                                        Dec 16 '18 at 12:47














                                                      4












                                                      4








                                                      4






                                                      APL+WIN, 41,32 30 bytes



                                                      9 bytes saved thanks to Erik + 2 more thanks to ngn



                                                      x←v-(+/v)÷⍴v←⎕⋄x÷(+/x×x÷⍴v)*.5


                                                      Prompts for vector of numbers and calculates mean standard deviation and standardised elements of input vector






                                                      share|improve this answer














                                                      APL+WIN, 41,32 30 bytes



                                                      9 bytes saved thanks to Erik + 2 more thanks to ngn



                                                      x←v-(+/v)÷⍴v←⎕⋄x÷(+/x×x÷⍴v)*.5


                                                      Prompts for vector of numbers and calculates mean standard deviation and standardised elements of input vector







                                                      share|improve this answer














                                                      share|improve this answer



                                                      share|improve this answer








                                                      edited Dec 16 '18 at 12:46

























                                                      answered Dec 14 '18 at 19:03









                                                      GrahamGraham

                                                      2,25678




                                                      2,25678












                                                      • Can't you assign x←v-(+/v)÷⍴v←⎕ and then do x÷((+/x*2)÷⍴v)*.5?
                                                        – Erik the Outgolfer
                                                        Dec 14 '18 at 19:11










                                                      • I can indeed. Thanks.
                                                        – Graham
                                                        Dec 14 '18 at 19:24










                                                      • does apl+win do singleton extension (1 2 3+,4 ←→ 1 2 3+4)? if yes, you could rewrite (+/x*2)÷⍴v as +/x×x÷⍴v
                                                        – ngn
                                                        Dec 16 '18 at 10:24










                                                      • @ngn That works for another 2 bytes. Thanks.
                                                        – Graham
                                                        Dec 16 '18 at 12:47


















                                                      • Can't you assign x←v-(+/v)÷⍴v←⎕ and then do x÷((+/x*2)÷⍴v)*.5?
                                                        – Erik the Outgolfer
                                                        Dec 14 '18 at 19:11










                                                      • I can indeed. Thanks.
                                                        – Graham
                                                        Dec 14 '18 at 19:24










                                                      • does apl+win do singleton extension (1 2 3+,4 ←→ 1 2 3+4)? if yes, you could rewrite (+/x*2)÷⍴v as +/x×x÷⍴v
                                                        – ngn
                                                        Dec 16 '18 at 10:24










                                                      • @ngn That works for another 2 bytes. Thanks.
                                                        – Graham
                                                        Dec 16 '18 at 12:47
















                                                      Can't you assign x←v-(+/v)÷⍴v←⎕ and then do x÷((+/x*2)÷⍴v)*.5?
                                                      – Erik the Outgolfer
                                                      Dec 14 '18 at 19:11




                                                      Can't you assign x←v-(+/v)÷⍴v←⎕ and then do x÷((+/x*2)÷⍴v)*.5?
                                                      – Erik the Outgolfer
                                                      Dec 14 '18 at 19:11












                                                      I can indeed. Thanks.
                                                      – Graham
                                                      Dec 14 '18 at 19:24




                                                      I can indeed. Thanks.
                                                      – Graham
                                                      Dec 14 '18 at 19:24












                                                      does apl+win do singleton extension (1 2 3+,4 ←→ 1 2 3+4)? if yes, you could rewrite (+/x*2)÷⍴v as +/x×x÷⍴v
                                                      – ngn
                                                      Dec 16 '18 at 10:24




                                                      does apl+win do singleton extension (1 2 3+,4 ←→ 1 2 3+4)? if yes, you could rewrite (+/x*2)÷⍴v as +/x×x÷⍴v
                                                      – ngn
                                                      Dec 16 '18 at 10:24












                                                      @ngn That works for another 2 bytes. Thanks.
                                                      – Graham
                                                      Dec 16 '18 at 12:47




                                                      @ngn That works for another 2 bytes. Thanks.
                                                      – Graham
                                                      Dec 16 '18 at 12:47











                                                      3















                                                      R + pryr, 53 52 bytes



                                                      -1 byte using sum(x|1) instead of length(x) as seen in @Robert S.'s solution





                                                      pryr::f((x-(y<-mean(x)))/(sum((x-y)^2)/sum(x|1))^.5)


                                                      For being a language built for statisticians, I'm amazed that this doesn't have a built-in function. At least not one that I could find. Even the function mosaic::zscore doesn't yield the expected results. This is likely due to using the population standard deviation instead of sample standard deviation.



                                                      Try it online!






                                                      share|improve this answer



















                                                      • 2




                                                        You can change the <- into a = to save 1 byte.
                                                        – Robert S.
                                                        Dec 14 '18 at 19:52










                                                      • @J.Doe nope, I used the method I commented on Robert S.'s solution. scale is neat!
                                                        – Giuseppe
                                                        Dec 14 '18 at 19:57






                                                      • 2




                                                        @J.Doe since you only use n once you can use it directly for 38 bytes
                                                        – Giuseppe
                                                        Dec 14 '18 at 20:00








                                                      • 2




                                                        @RobertS. here on PPCG we tend to encourage allowing flexible input and output, including outputting more than is required, with the exception of challenges where the precise layout of the output is the whole point of the challenge.
                                                        – ngm
                                                        Dec 14 '18 at 21:09






                                                      • 6




                                                        Of course R built-ins wouldn't use "population variance". Only confused engineers would use such a thing (hencethe Python and Matlab answers ;))
                                                        – ngm
                                                        Dec 14 '18 at 21:12
















                                                      3















                                                      R + pryr, 53 52 bytes



                                                      -1 byte using sum(x|1) instead of length(x) as seen in @Robert S.'s solution





                                                      pryr::f((x-(y<-mean(x)))/(sum((x-y)^2)/sum(x|1))^.5)


                                                      For being a language built for statisticians, I'm amazed that this doesn't have a built-in function. At least not one that I could find. Even the function mosaic::zscore doesn't yield the expected results. This is likely due to using the population standard deviation instead of sample standard deviation.



                                                      Try it online!






                                                      share|improve this answer



















                                                      • 2




                                                        You can change the <- into a = to save 1 byte.
                                                        – Robert S.
                                                        Dec 14 '18 at 19:52










                                                      • @J.Doe nope, I used the method I commented on Robert S.'s solution. scale is neat!
                                                        – Giuseppe
                                                        Dec 14 '18 at 19:57






                                                      • 2




                                                        @J.Doe since you only use n once you can use it directly for 38 bytes
                                                        – Giuseppe
                                                        Dec 14 '18 at 20:00








                                                      • 2




                                                        @RobertS. here on PPCG we tend to encourage allowing flexible input and output, including outputting more than is required, with the exception of challenges where the precise layout of the output is the whole point of the challenge.
                                                        – ngm
                                                        Dec 14 '18 at 21:09






                                                      • 6




                                                        Of course R built-ins wouldn't use "population variance". Only confused engineers would use such a thing (hencethe Python and Matlab answers ;))
                                                        – ngm
                                                        Dec 14 '18 at 21:12














                                                      3












                                                      3








                                                      3







                                                      R + pryr, 53 52 bytes



                                                      -1 byte using sum(x|1) instead of length(x) as seen in @Robert S.'s solution





                                                      pryr::f((x-(y<-mean(x)))/(sum((x-y)^2)/sum(x|1))^.5)


                                                      For being a language built for statisticians, I'm amazed that this doesn't have a built-in function. At least not one that I could find. Even the function mosaic::zscore doesn't yield the expected results. This is likely due to using the population standard deviation instead of sample standard deviation.



                                                      Try it online!






                                                      share|improve this answer















                                                      R + pryr, 53 52 bytes



                                                      -1 byte using sum(x|1) instead of length(x) as seen in @Robert S.'s solution





                                                      pryr::f((x-(y<-mean(x)))/(sum((x-y)^2)/sum(x|1))^.5)


                                                      For being a language built for statisticians, I'm amazed that this doesn't have a built-in function. At least not one that I could find. Even the function mosaic::zscore doesn't yield the expected results. This is likely due to using the population standard deviation instead of sample standard deviation.



                                                      Try it online!







                                                      share|improve this answer














                                                      share|improve this answer



                                                      share|improve this answer








                                                      edited Dec 14 '18 at 19:43

























                                                      answered Dec 14 '18 at 19:36









                                                      Sumner18Sumner18

                                                      4007




                                                      4007








                                                      • 2




                                                        You can change the <- into a = to save 1 byte.
                                                        – Robert S.
                                                        Dec 14 '18 at 19:52










                                                      • @J.Doe nope, I used the method I commented on Robert S.'s solution. scale is neat!
                                                        – Giuseppe
                                                        Dec 14 '18 at 19:57






                                                      • 2




                                                        @J.Doe since you only use n once you can use it directly for 38 bytes
                                                        – Giuseppe
                                                        Dec 14 '18 at 20:00








                                                      • 2




                                                        @RobertS. here on PPCG we tend to encourage allowing flexible input and output, including outputting more than is required, with the exception of challenges where the precise layout of the output is the whole point of the challenge.
                                                        – ngm
                                                        Dec 14 '18 at 21:09






                                                      • 6




                                                        Of course R built-ins wouldn't use "population variance". Only confused engineers would use such a thing (hencethe Python and Matlab answers ;))
                                                        – ngm
                                                        Dec 14 '18 at 21:12














                                                      • 2




                                                        You can change the <- into a = to save 1 byte.
                                                        – Robert S.
                                                        Dec 14 '18 at 19:52










                                                      • @J.Doe nope, I used the method I commented on Robert S.'s solution. scale is neat!
                                                        – Giuseppe
                                                        Dec 14 '18 at 19:57






                                                      • 2




                                                        @J.Doe since you only use n once you can use it directly for 38 bytes
                                                        – Giuseppe
                                                        Dec 14 '18 at 20:00








                                                      • 2




                                                        @RobertS. here on PPCG we tend to encourage allowing flexible input and output, including outputting more than is required, with the exception of challenges where the precise layout of the output is the whole point of the challenge.
                                                        – ngm
                                                        Dec 14 '18 at 21:09






                                                      • 6




                                                        Of course R built-ins wouldn't use "population variance". Only confused engineers would use such a thing (hencethe Python and Matlab answers ;))
                                                        – ngm
                                                        Dec 14 '18 at 21:12








                                                      2




                                                      2




                                                      You can change the <- into a = to save 1 byte.
                                                      – Robert S.
                                                      Dec 14 '18 at 19:52




                                                      You can change the <- into a = to save 1 byte.
                                                      – Robert S.
                                                      Dec 14 '18 at 19:52












                                                      @J.Doe nope, I used the method I commented on Robert S.'s solution. scale is neat!
                                                      – Giuseppe
                                                      Dec 14 '18 at 19:57




                                                      @J.Doe nope, I used the method I commented on Robert S.'s solution. scale is neat!
                                                      – Giuseppe
                                                      Dec 14 '18 at 19:57




                                                      2




                                                      2




                                                      @J.Doe since you only use n once you can use it directly for 38 bytes
                                                      – Giuseppe
                                                      Dec 14 '18 at 20:00






                                                      @J.Doe since you only use n once you can use it directly for 38 bytes
                                                      – Giuseppe
                                                      Dec 14 '18 at 20:00






                                                      2




                                                      2




                                                      @RobertS. here on PPCG we tend to encourage allowing flexible input and output, including outputting more than is required, with the exception of challenges where the precise layout of the output is the whole point of the challenge.
                                                      – ngm
                                                      Dec 14 '18 at 21:09




                                                      @RobertS. here on PPCG we tend to encourage allowing flexible input and output, including outputting more than is required, with the exception of challenges where the precise layout of the output is the whole point of the challenge.
                                                      – ngm
                                                      Dec 14 '18 at 21:09




                                                      6




                                                      6




                                                      Of course R built-ins wouldn't use "population variance". Only confused engineers would use such a thing (hencethe Python and Matlab answers ;))
                                                      – ngm
                                                      Dec 14 '18 at 21:12




                                                      Of course R built-ins wouldn't use "population variance". Only confused engineers would use such a thing (hencethe Python and Matlab answers ;))
                                                      – ngm
                                                      Dec 14 '18 at 21:12











                                                      3















                                                      Tcl, 126 bytes



                                                      proc S L {lmap c $L {expr ($c-[set m ([join $L +])/[set n [llength $L]].])/sqrt(([join [lmap c $L {expr ($c-$m)**2}] +])/$n)}}


                                                      Try it online!






                                                      share|improve this answer




























                                                        3















                                                        Tcl, 126 bytes



                                                        proc S L {lmap c $L {expr ($c-[set m ([join $L +])/[set n [llength $L]].])/sqrt(([join [lmap c $L {expr ($c-$m)**2}] +])/$n)}}


                                                        Try it online!






                                                        share|improve this answer


























                                                          3












                                                          3








                                                          3







                                                          Tcl, 126 bytes



                                                          proc S L {lmap c $L {expr ($c-[set m ([join $L +])/[set n [llength $L]].])/sqrt(([join [lmap c $L {expr ($c-$m)**2}] +])/$n)}}


                                                          Try it online!






                                                          share|improve this answer















                                                          Tcl, 126 bytes



                                                          proc S L {lmap c $L {expr ($c-[set m ([join $L +])/[set n [llength $L]].])/sqrt(([join [lmap c $L {expr ($c-$m)**2}] +])/$n)}}


                                                          Try it online!







                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Dec 15 '18 at 19:14

























                                                          answered Dec 14 '18 at 20:06









                                                          sergiolsergiol

                                                          2,5021925




                                                          2,5021925























                                                              2















                                                              Jelly, 10 bytes



                                                              _ÆmµL½÷ÆḊ×


                                                              Try it online!



                                                              It's not any shorter, but Jelly's determinant function ÆḊ also calculates vector norm.



                                                              _Æm             x - mean(x)
                                                              µ then:
                                                              L½ Square root of the Length
                                                              ÷ÆḊ divided by the norm
                                                              × Multiply by that value





                                                              share|improve this answer





















                                                              • Hey, nice alternative! Unfortunately, I can't see a way to shorten it.
                                                                – Erik the Outgolfer
                                                                Dec 14 '18 at 22:34
















                                                              2















                                                              Jelly, 10 bytes



                                                              _ÆmµL½÷ÆḊ×


                                                              Try it online!



                                                              It's not any shorter, but Jelly's determinant function ÆḊ also calculates vector norm.



                                                              _Æm             x - mean(x)
                                                              µ then:
                                                              L½ Square root of the Length
                                                              ÷ÆḊ divided by the norm
                                                              × Multiply by that value





                                                              share|improve this answer





















                                                              • Hey, nice alternative! Unfortunately, I can't see a way to shorten it.
                                                                – Erik the Outgolfer
                                                                Dec 14 '18 at 22:34














                                                              2












                                                              2








                                                              2







                                                              Jelly, 10 bytes



                                                              _ÆmµL½÷ÆḊ×


                                                              Try it online!



                                                              It's not any shorter, but Jelly's determinant function ÆḊ also calculates vector norm.



                                                              _Æm             x - mean(x)
                                                              µ then:
                                                              L½ Square root of the Length
                                                              ÷ÆḊ divided by the norm
                                                              × Multiply by that value





                                                              share|improve this answer













                                                              Jelly, 10 bytes



                                                              _ÆmµL½÷ÆḊ×


                                                              Try it online!



                                                              It's not any shorter, but Jelly's determinant function ÆḊ also calculates vector norm.



                                                              _Æm             x - mean(x)
                                                              µ then:
                                                              L½ Square root of the Length
                                                              ÷ÆḊ divided by the norm
                                                              × Multiply by that value






                                                              share|improve this answer












                                                              share|improve this answer



                                                              share|improve this answer










                                                              answered Dec 14 '18 at 20:31









                                                              lirtosiastlirtosiast

                                                              15.7k436107




                                                              15.7k436107












                                                              • Hey, nice alternative! Unfortunately, I can't see a way to shorten it.
                                                                – Erik the Outgolfer
                                                                Dec 14 '18 at 22:34


















                                                              • Hey, nice alternative! Unfortunately, I can't see a way to shorten it.
                                                                – Erik the Outgolfer
                                                                Dec 14 '18 at 22:34
















                                                              Hey, nice alternative! Unfortunately, I can't see a way to shorten it.
                                                              – Erik the Outgolfer
                                                              Dec 14 '18 at 22:34




                                                              Hey, nice alternative! Unfortunately, I can't see a way to shorten it.
                                                              – Erik the Outgolfer
                                                              Dec 14 '18 at 22:34











                                                              2














                                                              Mathematica, 25 bytes



                                                              Mean[(a=#-Mean@#)a]^-.5a&


                                                              Pure function. Takes a list of numbers as input and returns a list of machine-precision numbers as output. Note that the built-in Standardize function uses the sample variance by default.






                                                              share|improve this answer


























                                                                2














                                                                Mathematica, 25 bytes



                                                                Mean[(a=#-Mean@#)a]^-.5a&


                                                                Pure function. Takes a list of numbers as input and returns a list of machine-precision numbers as output. Note that the built-in Standardize function uses the sample variance by default.






                                                                share|improve this answer
























                                                                  2












                                                                  2








                                                                  2






                                                                  Mathematica, 25 bytes



                                                                  Mean[(a=#-Mean@#)a]^-.5a&


                                                                  Pure function. Takes a list of numbers as input and returns a list of machine-precision numbers as output. Note that the built-in Standardize function uses the sample variance by default.






                                                                  share|improve this answer












                                                                  Mathematica, 25 bytes



                                                                  Mean[(a=#-Mean@#)a]^-.5a&


                                                                  Pure function. Takes a list of numbers as input and returns a list of machine-precision numbers as output. Note that the built-in Standardize function uses the sample variance by default.







                                                                  share|improve this answer












                                                                  share|improve this answer



                                                                  share|improve this answer










                                                                  answered Dec 15 '18 at 0:26









                                                                  LegionMammal978LegionMammal978

                                                                  15.1k41852




                                                                  15.1k41852























                                                                      2















                                                                      J, 22 bytes



                                                                      -1 byte thanks to Cows quack!



                                                                      (-%[:%:1#.-*-%#@[)+/%#


                                                                      Try it online!




                                                                      J, 31 23 bytes



                                                                      (-%[:%:#@[%~1#.-*-)+/%#


                                                                      Try it online!



                                                                                         +/%# - mean (sum (+/) divided (%) by the number of samples (#)) 
                                                                      ( ) - the list is a left argument here (we have a hook)
                                                                      - - the difference between each sample and the mean
                                                                      * - multiplied by
                                                                      - - the difference between each sample and the mean
                                                                      1#. - sum by base-1 conversion
                                                                      %~ - divided by
                                                                      #@[ - the length of the samples list
                                                                      %: - square root
                                                                      [: - convert to a fork (function composition)
                                                                      - - subtract the mean from each sample
                                                                      % - and divide it by sigma





                                                                      share|improve this answer



















                                                                      • 1




                                                                        Rearranging it gives 22 [:(%[:%:1#.*:%#)]-+/%# tio.run/##y/qfVmyrp2CgYKVg8D/…, I think one of those caps could be removed, but haven't had any luck so far, EDIT: a more direct byteshaving is (-%[:%:1#.-*-%#@[)+/%# also at 22
                                                                        – Cows quack
                                                                        Dec 15 '18 at 13:12












                                                                      • @Cows quack Thanks!
                                                                        – Galen Ivanov
                                                                        Dec 15 '18 at 14:30
















                                                                      2















                                                                      J, 22 bytes



                                                                      -1 byte thanks to Cows quack!



                                                                      (-%[:%:1#.-*-%#@[)+/%#


                                                                      Try it online!




                                                                      J, 31 23 bytes



                                                                      (-%[:%:#@[%~1#.-*-)+/%#


                                                                      Try it online!



                                                                                         +/%# - mean (sum (+/) divided (%) by the number of samples (#)) 
                                                                      ( ) - the list is a left argument here (we have a hook)
                                                                      - - the difference between each sample and the mean
                                                                      * - multiplied by
                                                                      - - the difference between each sample and the mean
                                                                      1#. - sum by base-1 conversion
                                                                      %~ - divided by
                                                                      #@[ - the length of the samples list
                                                                      %: - square root
                                                                      [: - convert to a fork (function composition)
                                                                      - - subtract the mean from each sample
                                                                      % - and divide it by sigma





                                                                      share|improve this answer



















                                                                      • 1




                                                                        Rearranging it gives 22 [:(%[:%:1#.*:%#)]-+/%# tio.run/##y/qfVmyrp2CgYKVg8D/…, I think one of those caps could be removed, but haven't had any luck so far, EDIT: a more direct byteshaving is (-%[:%:1#.-*-%#@[)+/%# also at 22
                                                                        – Cows quack
                                                                        Dec 15 '18 at 13:12












                                                                      • @Cows quack Thanks!
                                                                        – Galen Ivanov
                                                                        Dec 15 '18 at 14:30














                                                                      2












                                                                      2








                                                                      2







                                                                      J, 22 bytes



                                                                      -1 byte thanks to Cows quack!



                                                                      (-%[:%:1#.-*-%#@[)+/%#


                                                                      Try it online!




                                                                      J, 31 23 bytes



                                                                      (-%[:%:#@[%~1#.-*-)+/%#


                                                                      Try it online!



                                                                                         +/%# - mean (sum (+/) divided (%) by the number of samples (#)) 
                                                                      ( ) - the list is a left argument here (we have a hook)
                                                                      - - the difference between each sample and the mean
                                                                      * - multiplied by
                                                                      - - the difference between each sample and the mean
                                                                      1#. - sum by base-1 conversion
                                                                      %~ - divided by
                                                                      #@[ - the length of the samples list
                                                                      %: - square root
                                                                      [: - convert to a fork (function composition)
                                                                      - - subtract the mean from each sample
                                                                      % - and divide it by sigma





                                                                      share|improve this answer















                                                                      J, 22 bytes



                                                                      -1 byte thanks to Cows quack!



                                                                      (-%[:%:1#.-*-%#@[)+/%#


                                                                      Try it online!




                                                                      J, 31 23 bytes



                                                                      (-%[:%:#@[%~1#.-*-)+/%#


                                                                      Try it online!



                                                                                         +/%# - mean (sum (+/) divided (%) by the number of samples (#)) 
                                                                      ( ) - the list is a left argument here (we have a hook)
                                                                      - - the difference between each sample and the mean
                                                                      * - multiplied by
                                                                      - - the difference between each sample and the mean
                                                                      1#. - sum by base-1 conversion
                                                                      %~ - divided by
                                                                      #@[ - the length of the samples list
                                                                      %: - square root
                                                                      [: - convert to a fork (function composition)
                                                                      - - subtract the mean from each sample
                                                                      % - and divide it by sigma






                                                                      share|improve this answer














                                                                      share|improve this answer



                                                                      share|improve this answer








                                                                      edited Dec 15 '18 at 14:28

























                                                                      answered Dec 15 '18 at 9:49









                                                                      Galen IvanovGalen Ivanov

                                                                      6,41711032




                                                                      6,41711032








                                                                      • 1




                                                                        Rearranging it gives 22 [:(%[:%:1#.*:%#)]-+/%# tio.run/##y/qfVmyrp2CgYKVg8D/…, I think one of those caps could be removed, but haven't had any luck so far, EDIT: a more direct byteshaving is (-%[:%:1#.-*-%#@[)+/%# also at 22
                                                                        – Cows quack
                                                                        Dec 15 '18 at 13:12












                                                                      • @Cows quack Thanks!
                                                                        – Galen Ivanov
                                                                        Dec 15 '18 at 14:30














                                                                      • 1




                                                                        Rearranging it gives 22 [:(%[:%:1#.*:%#)]-+/%# tio.run/##y/qfVmyrp2CgYKVg8D/…, I think one of those caps could be removed, but haven't had any luck so far, EDIT: a more direct byteshaving is (-%[:%:1#.-*-%#@[)+/%# also at 22
                                                                        – Cows quack
                                                                        Dec 15 '18 at 13:12












                                                                      • @Cows quack Thanks!
                                                                        – Galen Ivanov
                                                                        Dec 15 '18 at 14:30








                                                                      1




                                                                      1




                                                                      Rearranging it gives 22 [:(%[:%:1#.*:%#)]-+/%# tio.run/##y/qfVmyrp2CgYKVg8D/…, I think one of those caps could be removed, but haven't had any luck so far, EDIT: a more direct byteshaving is (-%[:%:1#.-*-%#@[)+/%# also at 22
                                                                      – Cows quack
                                                                      Dec 15 '18 at 13:12






                                                                      Rearranging it gives 22 [:(%[:%:1#.*:%#)]-+/%# tio.run/##y/qfVmyrp2CgYKVg8D/…, I think one of those caps could be removed, but haven't had any luck so far, EDIT: a more direct byteshaving is (-%[:%:1#.-*-%#@[)+/%# also at 22
                                                                      – Cows quack
                                                                      Dec 15 '18 at 13:12














                                                                      @Cows quack Thanks!
                                                                      – Galen Ivanov
                                                                      Dec 15 '18 at 14:30




                                                                      @Cows quack Thanks!
                                                                      – Galen Ivanov
                                                                      Dec 15 '18 at 14:30











                                                                      2















                                                                      APL (Dyalog Unicode), 33 29 bytes





                                                                      {d÷.5*⍨l÷⍨+/×⍨d←⍵-(+/⍵)÷l←≢⍵}


                                                                      -4 bytes thanks to @ngn



                                                                      Try it online!






                                                                      share|improve this answer























                                                                      • you could assign ⍵-m to a variable and remove m← like this: {d÷.5*⍨l÷⍨+/×⍨d←⍵-(+/⍵)÷l←≢⍵}
                                                                        – ngn
                                                                        Dec 16 '18 at 10:39










                                                                      • @ngn Ah, nice, thanks, I didn't see that duplication somehow
                                                                        – Quintec
                                                                        Dec 16 '18 at 16:15
















                                                                      2















                                                                      APL (Dyalog Unicode), 33 29 bytes





                                                                      {d÷.5*⍨l÷⍨+/×⍨d←⍵-(+/⍵)÷l←≢⍵}


                                                                      -4 bytes thanks to @ngn



                                                                      Try it online!






                                                                      share|improve this answer























                                                                      • you could assign ⍵-m to a variable and remove m← like this: {d÷.5*⍨l÷⍨+/×⍨d←⍵-(+/⍵)÷l←≢⍵}
                                                                        – ngn
                                                                        Dec 16 '18 at 10:39










                                                                      • @ngn Ah, nice, thanks, I didn't see that duplication somehow
                                                                        – Quintec
                                                                        Dec 16 '18 at 16:15














                                                                      2












                                                                      2








                                                                      2







                                                                      APL (Dyalog Unicode), 33 29 bytes





                                                                      {d÷.5*⍨l÷⍨+/×⍨d←⍵-(+/⍵)÷l←≢⍵}


                                                                      -4 bytes thanks to @ngn



                                                                      Try it online!






                                                                      share|improve this answer















                                                                      APL (Dyalog Unicode), 33 29 bytes





                                                                      {d÷.5*⍨l÷⍨+/×⍨d←⍵-(+/⍵)÷l←≢⍵}


                                                                      -4 bytes thanks to @ngn



                                                                      Try it online!







                                                                      share|improve this answer














                                                                      share|improve this answer



                                                                      share|improve this answer








                                                                      edited Dec 16 '18 at 16:15

























                                                                      answered Dec 14 '18 at 19:09









                                                                      QuintecQuintec

                                                                      1,4881722




                                                                      1,4881722












                                                                      • you could assign ⍵-m to a variable and remove m← like this: {d÷.5*⍨l÷⍨+/×⍨d←⍵-(+/⍵)÷l←≢⍵}
                                                                        – ngn
                                                                        Dec 16 '18 at 10:39










                                                                      • @ngn Ah, nice, thanks, I didn't see that duplication somehow
                                                                        – Quintec
                                                                        Dec 16 '18 at 16:15


















                                                                      • you could assign ⍵-m to a variable and remove m← like this: {d÷.5*⍨l÷⍨+/×⍨d←⍵-(+/⍵)÷l←≢⍵}
                                                                        – ngn
                                                                        Dec 16 '18 at 10:39










                                                                      • @ngn Ah, nice, thanks, I didn't see that duplication somehow
                                                                        – Quintec
                                                                        Dec 16 '18 at 16:15
















                                                                      you could assign ⍵-m to a variable and remove m← like this: {d÷.5*⍨l÷⍨+/×⍨d←⍵-(+/⍵)÷l←≢⍵}
                                                                      – ngn
                                                                      Dec 16 '18 at 10:39




                                                                      you could assign ⍵-m to a variable and remove m← like this: {d÷.5*⍨l÷⍨+/×⍨d←⍵-(+/⍵)÷l←≢⍵}
                                                                      – ngn
                                                                      Dec 16 '18 at 10:39












                                                                      @ngn Ah, nice, thanks, I didn't see that duplication somehow
                                                                      – Quintec
                                                                      Dec 16 '18 at 16:15




                                                                      @ngn Ah, nice, thanks, I didn't see that duplication somehow
                                                                      – Quintec
                                                                      Dec 16 '18 at 16:15











                                                                      2














                                                                      Haskell, 80 75 68 bytes



                                                                      t x=k(/sqrt(f$sum$k(^2)))where k g=g.(-f(sum x)+)<$>x;f=(/sum(1<$x))


                                                                      Thanks to @flawr for the suggestions to use sum(1<$x) instead of sum[1|_<-x] and to inline the mean, @xnor for inlining the standard deviation and other reductions.



                                                                      Expanded:



                                                                      -- Standardize a list of values of any floating-point type.
                                                                      standardize :: Floating a => [a] -> [a]
                                                                      standardize input = eachLessMean (/ sqrt (overLength (sum (eachLessMean (^2)))))
                                                                      where

                                                                      -- Map a function over each element of the input, less the mean.
                                                                      eachLessMean f = map (f . subtract (overLength (sum input))) input

                                                                      -- Divide a value by the length of the input.
                                                                      overLength n = n / sum (map (const 1) input)





                                                                      share|improve this answer



















                                                                      • 1




                                                                        You can replace [1|_<-x] with (1<$x) to save a few bytes. That is a great trick for avoiding the fromIntegral, that I haven't seen so far!
                                                                        – flawr
                                                                        Dec 16 '18 at 10:54












                                                                      • By the way: I like using tryitonline, you can run your code there and then copy the preformatted aswer for posting here!
                                                                        – flawr
                                                                        Dec 16 '18 at 10:57










                                                                      • And you do not have to define m.
                                                                        – flawr
                                                                        Dec 16 '18 at 11:02












                                                                      • You can write (-x+) for (+(-x)) to avoid parens. Also it looks like f can be pointfree: f=(/sum(1<$x)), and s can be replaced with its definition.
                                                                        – xnor
                                                                        Dec 16 '18 at 20:00












                                                                      • @xnor Ooh, (-x+) is handy, I’m sure I’ll be using that in the future
                                                                        – Jon Purdy
                                                                        Dec 16 '18 at 21:15
















                                                                      2














                                                                      Haskell, 80 75 68 bytes



                                                                      t x=k(/sqrt(f$sum$k(^2)))where k g=g.(-f(sum x)+)<$>x;f=(/sum(1<$x))


                                                                      Thanks to @flawr for the suggestions to use sum(1<$x) instead of sum[1|_<-x] and to inline the mean, @xnor for inlining the standard deviation and other reductions.



                                                                      Expanded:



                                                                      -- Standardize a list of values of any floating-point type.
                                                                      standardize :: Floating a => [a] -> [a]
                                                                      standardize input = eachLessMean (/ sqrt (overLength (sum (eachLessMean (^2)))))
                                                                      where

                                                                      -- Map a function over each element of the input, less the mean.
                                                                      eachLessMean f = map (f . subtract (overLength (sum input))) input

                                                                      -- Divide a value by the length of the input.
                                                                      overLength n = n / sum (map (const 1) input)





                                                                      share|improve this answer



















                                                                      • 1




                                                                        You can replace [1|_<-x] with (1<$x) to save a few bytes. That is a great trick for avoiding the fromIntegral, that I haven't seen so far!
                                                                        – flawr
                                                                        Dec 16 '18 at 10:54












                                                                      • By the way: I like using tryitonline, you can run your code there and then copy the preformatted aswer for posting here!
                                                                        – flawr
                                                                        Dec 16 '18 at 10:57










                                                                      • And you do not have to define m.
                                                                        – flawr
                                                                        Dec 16 '18 at 11:02












                                                                      • You can write (-x+) for (+(-x)) to avoid parens. Also it looks like f can be pointfree: f=(/sum(1<$x)), and s can be replaced with its definition.
                                                                        – xnor
                                                                        Dec 16 '18 at 20:00












                                                                      • @xnor Ooh, (-x+) is handy, I’m sure I’ll be using that in the future
                                                                        – Jon Purdy
                                                                        Dec 16 '18 at 21:15














                                                                      2












                                                                      2








                                                                      2






                                                                      Haskell, 80 75 68 bytes



                                                                      t x=k(/sqrt(f$sum$k(^2)))where k g=g.(-f(sum x)+)<$>x;f=(/sum(1<$x))


                                                                      Thanks to @flawr for the suggestions to use sum(1<$x) instead of sum[1|_<-x] and to inline the mean, @xnor for inlining the standard deviation and other reductions.



                                                                      Expanded:



                                                                      -- Standardize a list of values of any floating-point type.
                                                                      standardize :: Floating a => [a] -> [a]
                                                                      standardize input = eachLessMean (/ sqrt (overLength (sum (eachLessMean (^2)))))
                                                                      where

                                                                      -- Map a function over each element of the input, less the mean.
                                                                      eachLessMean f = map (f . subtract (overLength (sum input))) input

                                                                      -- Divide a value by the length of the input.
                                                                      overLength n = n / sum (map (const 1) input)





                                                                      share|improve this answer














                                                                      Haskell, 80 75 68 bytes



                                                                      t x=k(/sqrt(f$sum$k(^2)))where k g=g.(-f(sum x)+)<$>x;f=(/sum(1<$x))


                                                                      Thanks to @flawr for the suggestions to use sum(1<$x) instead of sum[1|_<-x] and to inline the mean, @xnor for inlining the standard deviation and other reductions.



                                                                      Expanded:



                                                                      -- Standardize a list of values of any floating-point type.
                                                                      standardize :: Floating a => [a] -> [a]
                                                                      standardize input = eachLessMean (/ sqrt (overLength (sum (eachLessMean (^2)))))
                                                                      where

                                                                      -- Map a function over each element of the input, less the mean.
                                                                      eachLessMean f = map (f . subtract (overLength (sum input))) input

                                                                      -- Divide a value by the length of the input.
                                                                      overLength n = n / sum (map (const 1) input)






                                                                      share|improve this answer














                                                                      share|improve this answer



                                                                      share|improve this answer








                                                                      edited Dec 16 '18 at 21:17

























                                                                      answered Dec 16 '18 at 6:28









                                                                      Jon PurdyJon Purdy

                                                                      47128




                                                                      47128








                                                                      • 1




                                                                        You can replace [1|_<-x] with (1<$x) to save a few bytes. That is a great trick for avoiding the fromIntegral, that I haven't seen so far!
                                                                        – flawr
                                                                        Dec 16 '18 at 10:54












                                                                      • By the way: I like using tryitonline, you can run your code there and then copy the preformatted aswer for posting here!
                                                                        – flawr
                                                                        Dec 16 '18 at 10:57










                                                                      • And you do not have to define m.
                                                                        – flawr
                                                                        Dec 16 '18 at 11:02












                                                                      • You can write (-x+) for (+(-x)) to avoid parens. Also it looks like f can be pointfree: f=(/sum(1<$x)), and s can be replaced with its definition.
                                                                        – xnor
                                                                        Dec 16 '18 at 20:00












                                                                      • @xnor Ooh, (-x+) is handy, I’m sure I’ll be using that in the future
                                                                        – Jon Purdy
                                                                        Dec 16 '18 at 21:15














                                                                      • 1




                                                                        You can replace [1|_<-x] with (1<$x) to save a few bytes. That is a great trick for avoiding the fromIntegral, that I haven't seen so far!
                                                                        – flawr
                                                                        Dec 16 '18 at 10:54












                                                                      • By the way: I like using tryitonline, you can run your code there and then copy the preformatted aswer for posting here!
                                                                        – flawr
                                                                        Dec 16 '18 at 10:57










                                                                      • And you do not have to define m.
                                                                        – flawr
                                                                        Dec 16 '18 at 11:02












                                                                      • You can write (-x+) for (+(-x)) to avoid parens. Also it looks like f can be pointfree: f=(/sum(1<$x)), and s can be replaced with its definition.
                                                                        – xnor
                                                                        Dec 16 '18 at 20:00












                                                                      • @xnor Ooh, (-x+) is handy, I’m sure I’ll be using that in the future
                                                                        – Jon Purdy
                                                                        Dec 16 '18 at 21:15








                                                                      1




                                                                      1




                                                                      You can replace [1|_<-x] with (1<$x) to save a few bytes. That is a great trick for avoiding the fromIntegral, that I haven't seen so far!
                                                                      – flawr
                                                                      Dec 16 '18 at 10:54






                                                                      You can replace [1|_<-x] with (1<$x) to save a few bytes. That is a great trick for avoiding the fromIntegral, that I haven't seen so far!
                                                                      – flawr
                                                                      Dec 16 '18 at 10:54














                                                                      By the way: I like using tryitonline, you can run your code there and then copy the preformatted aswer for posting here!
                                                                      – flawr
                                                                      Dec 16 '18 at 10:57




                                                                      By the way: I like using tryitonline, you can run your code there and then copy the preformatted aswer for posting here!
                                                                      – flawr
                                                                      Dec 16 '18 at 10:57












                                                                      And you do not have to define m.
                                                                      – flawr
                                                                      Dec 16 '18 at 11:02






                                                                      And you do not have to define m.
                                                                      – flawr
                                                                      Dec 16 '18 at 11:02














                                                                      You can write (-x+) for (+(-x)) to avoid parens. Also it looks like f can be pointfree: f=(/sum(1<$x)), and s can be replaced with its definition.
                                                                      – xnor
                                                                      Dec 16 '18 at 20:00






                                                                      You can write (-x+) for (+(-x)) to avoid parens. Also it looks like f can be pointfree: f=(/sum(1<$x)), and s can be replaced with its definition.
                                                                      – xnor
                                                                      Dec 16 '18 at 20:00














                                                                      @xnor Ooh, (-x+) is handy, I’m sure I’ll be using that in the future
                                                                      – Jon Purdy
                                                                      Dec 16 '18 at 21:15




                                                                      @xnor Ooh, (-x+) is handy, I’m sure I’ll be using that in the future
                                                                      – Jon Purdy
                                                                      Dec 16 '18 at 21:15











                                                                      2















                                                                      MathGolf, 7 bytes



                                                                      ▓-_²▓√/


                                                                      Try it online!



                                                                      Explanation



                                                                      This is literally a byte-for-byte recreation of Kevin Cruijssen's 05AB1E answer, but I save some bytes from MathGolf having 1-byters for everything needed for this challenge. Also the answer looks quite good in my opinion!



                                                                      ▓         get average of list
                                                                      - pop a, b : push(a-b)
                                                                      _ duplicate TOS
                                                                      ² pop a : push(a*a)
                                                                      ▓ get average of list
                                                                      √ pop a : push(sqrt(a)), split string to list
                                                                      / pop a, b : push(a/b), split strings





                                                                      share|improve this answer


























                                                                        2















                                                                        MathGolf, 7 bytes



                                                                        ▓-_²▓√/


                                                                        Try it online!



                                                                        Explanation



                                                                        This is literally a byte-for-byte recreation of Kevin Cruijssen's 05AB1E answer, but I save some bytes from MathGolf having 1-byters for everything needed for this challenge. Also the answer looks quite good in my opinion!



                                                                        ▓         get average of list
                                                                        - pop a, b : push(a-b)
                                                                        _ duplicate TOS
                                                                        ² pop a : push(a*a)
                                                                        ▓ get average of list
                                                                        √ pop a : push(sqrt(a)), split string to list
                                                                        / pop a, b : push(a/b), split strings





                                                                        share|improve this answer
























                                                                          2












                                                                          2








                                                                          2







                                                                          MathGolf, 7 bytes



                                                                          ▓-_²▓√/


                                                                          Try it online!



                                                                          Explanation



                                                                          This is literally a byte-for-byte recreation of Kevin Cruijssen's 05AB1E answer, but I save some bytes from MathGolf having 1-byters for everything needed for this challenge. Also the answer looks quite good in my opinion!



                                                                          ▓         get average of list
                                                                          - pop a, b : push(a-b)
                                                                          _ duplicate TOS
                                                                          ² pop a : push(a*a)
                                                                          ▓ get average of list
                                                                          √ pop a : push(sqrt(a)), split string to list
                                                                          / pop a, b : push(a/b), split strings





                                                                          share|improve this answer













                                                                          MathGolf, 7 bytes



                                                                          ▓-_²▓√/


                                                                          Try it online!



                                                                          Explanation



                                                                          This is literally a byte-for-byte recreation of Kevin Cruijssen's 05AB1E answer, but I save some bytes from MathGolf having 1-byters for everything needed for this challenge. Also the answer looks quite good in my opinion!



                                                                          ▓         get average of list
                                                                          - pop a, b : push(a-b)
                                                                          _ duplicate TOS
                                                                          ² pop a : push(a*a)
                                                                          ▓ get average of list
                                                                          √ pop a : push(sqrt(a)), split string to list
                                                                          / pop a, b : push(a/b), split strings






                                                                          share|improve this answer












                                                                          share|improve this answer



                                                                          share|improve this answer










                                                                          answered Dec 17 '18 at 14:55









                                                                          maxbmaxb

                                                                          2,94811132




                                                                          2,94811132























                                                                              1














                                                                              JavaScript (ES7),  80  79 bytes





                                                                              a=>a.map(x=>(x-g(a))/g(a.map(x=>(x-m)**2))**.5,g=a=>m=eval(a.join`+`)/a.length)


                                                                              Try it online!



                                                                              Commented



                                                                              a =>                      // given the input array a
                                                                              a.map(x => // for each value x in a:
                                                                              (x - g(a)) / // compute (x - mean(a)) divided by
                                                                              g( // the standard deviation:
                                                                              a.map(x => // for each value x in a:
                                                                              (x - m) ** 2 // compute (x - mean(a))²
                                                                              ) // compute the mean of this array
                                                                              ) ** .5, // and take the square root
                                                                              g = a => // g = helper function taking an array a,
                                                                              m = eval(a.join`+`) // computing the mean
                                                                              / a.length // and storing the result in m
                                                                              ) // end of outer map()





                                                                              share|improve this answer




























                                                                                1














                                                                                JavaScript (ES7),  80  79 bytes





                                                                                a=>a.map(x=>(x-g(a))/g(a.map(x=>(x-m)**2))**.5,g=a=>m=eval(a.join`+`)/a.length)


                                                                                Try it online!



                                                                                Commented



                                                                                a =>                      // given the input array a
                                                                                a.map(x => // for each value x in a:
                                                                                (x - g(a)) / // compute (x - mean(a)) divided by
                                                                                g( // the standard deviation:
                                                                                a.map(x => // for each value x in a:
                                                                                (x - m) ** 2 // compute (x - mean(a))²
                                                                                ) // compute the mean of this array
                                                                                ) ** .5, // and take the square root
                                                                                g = a => // g = helper function taking an array a,
                                                                                m = eval(a.join`+`) // computing the mean
                                                                                / a.length // and storing the result in m
                                                                                ) // end of outer map()





                                                                                share|improve this answer


























                                                                                  1












                                                                                  1








                                                                                  1






                                                                                  JavaScript (ES7),  80  79 bytes





                                                                                  a=>a.map(x=>(x-g(a))/g(a.map(x=>(x-m)**2))**.5,g=a=>m=eval(a.join`+`)/a.length)


                                                                                  Try it online!



                                                                                  Commented



                                                                                  a =>                      // given the input array a
                                                                                  a.map(x => // for each value x in a:
                                                                                  (x - g(a)) / // compute (x - mean(a)) divided by
                                                                                  g( // the standard deviation:
                                                                                  a.map(x => // for each value x in a:
                                                                                  (x - m) ** 2 // compute (x - mean(a))²
                                                                                  ) // compute the mean of this array
                                                                                  ) ** .5, // and take the square root
                                                                                  g = a => // g = helper function taking an array a,
                                                                                  m = eval(a.join`+`) // computing the mean
                                                                                  / a.length // and storing the result in m
                                                                                  ) // end of outer map()





                                                                                  share|improve this answer














                                                                                  JavaScript (ES7),  80  79 bytes





                                                                                  a=>a.map(x=>(x-g(a))/g(a.map(x=>(x-m)**2))**.5,g=a=>m=eval(a.join`+`)/a.length)


                                                                                  Try it online!



                                                                                  Commented



                                                                                  a =>                      // given the input array a
                                                                                  a.map(x => // for each value x in a:
                                                                                  (x - g(a)) / // compute (x - mean(a)) divided by
                                                                                  g( // the standard deviation:
                                                                                  a.map(x => // for each value x in a:
                                                                                  (x - m) ** 2 // compute (x - mean(a))²
                                                                                  ) // compute the mean of this array
                                                                                  ) ** .5, // and take the square root
                                                                                  g = a => // g = helper function taking an array a,
                                                                                  m = eval(a.join`+`) // computing the mean
                                                                                  / a.length // and storing the result in m
                                                                                  ) // end of outer map()






                                                                                  share|improve this answer














                                                                                  share|improve this answer



                                                                                  share|improve this answer








                                                                                  edited Dec 14 '18 at 23:42

























                                                                                  answered Dec 14 '18 at 18:59









                                                                                  ArnauldArnauld

                                                                                  72.8k689307




                                                                                  72.8k689307























                                                                                      1















                                                                                      Python 3 + numpy, 46 bytes





                                                                                      lambda a:(a-mean(a))/std(a)
                                                                                      from numpy import*


                                                                                      Try it online!






                                                                                      share|improve this answer




























                                                                                        1















                                                                                        Python 3 + numpy, 46 bytes





                                                                                        lambda a:(a-mean(a))/std(a)
                                                                                        from numpy import*


                                                                                        Try it online!






                                                                                        share|improve this answer


























                                                                                          1












                                                                                          1








                                                                                          1







                                                                                          Python 3 + numpy, 46 bytes





                                                                                          lambda a:(a-mean(a))/std(a)
                                                                                          from numpy import*


                                                                                          Try it online!






                                                                                          share|improve this answer















                                                                                          Python 3 + numpy, 46 bytes





                                                                                          lambda a:(a-mean(a))/std(a)
                                                                                          from numpy import*


                                                                                          Try it online!







                                                                                          share|improve this answer














                                                                                          share|improve this answer



                                                                                          share|improve this answer








                                                                                          edited Dec 15 '18 at 16:25

























                                                                                          answered Dec 15 '18 at 12:29









                                                                                          ovsovs

                                                                                          18.7k21159




                                                                                          18.7k21159























                                                                                              1















                                                                                              Haskell, 59 bytes





                                                                                              (%)i=sum.map(^i)
                                                                                              f l=[(0%l*y-1%l)/sqrt(2%l*0%l-1%l^2)|y<-l]


                                                                                              Try it online!



                                                                                              Doesn't use libraries.



                                                                                              The helper function % computes the sum of ith powers of a list, which lets us get three useful values.





                                                                                              • 0%l is the length of l (call this n)


                                                                                              • 1%l is the sum of l (call this s)


                                                                                              • 2%l is the sum of squares of l (call this m)


                                                                                              We can express the z-score of an element y as



                                                                                              (n*y-s)/sqrt(n*v-s^2)


                                                                                              (This is the expression (y-s/n)/sqrt(v/n-(s/n)^2) simplified a bit by multiplying the top and bottom by n.)



                                                                                              We can insert the expressions 0%l, 1%l, 2%l without parens because the % we define has higher precedence than the arithmetic operators.



                                                                                              (%)i=sum.map(^i) is the same length as i%l=sum.map(^i)l. Making it more point-free doesn't help. Defining it like g i=... loses bytes when we call it. Although % works for any list but we only call it with the problem input list, there's no byte loss in calling it with argument l every time because a two-argument call i%l is no longer than a one-argument one g i.






                                                                                              share|improve this answer





















                                                                                              • We do have $LaTeX$ here:)
                                                                                                – flawr
                                                                                                Dec 16 '18 at 9:59










                                                                                              • I really like the % idea! It looks just like the discrete version of the statistical moments.
                                                                                                – flawr
                                                                                                Dec 16 '18 at 10:02
















                                                                                              1















                                                                                              Haskell, 59 bytes





                                                                                              (%)i=sum.map(^i)
                                                                                              f l=[(0%l*y-1%l)/sqrt(2%l*0%l-1%l^2)|y<-l]


                                                                                              Try it online!



                                                                                              Doesn't use libraries.



                                                                                              The helper function % computes the sum of ith powers of a list, which lets us get three useful values.





                                                                                              • 0%l is the length of l (call this n)


                                                                                              • 1%l is the sum of l (call this s)


                                                                                              • 2%l is the sum of squares of l (call this m)


                                                                                              We can express the z-score of an element y as



                                                                                              (n*y-s)/sqrt(n*v-s^2)


                                                                                              (This is the expression (y-s/n)/sqrt(v/n-(s/n)^2) simplified a bit by multiplying the top and bottom by n.)



                                                                                              We can insert the expressions 0%l, 1%l, 2%l without parens because the % we define has higher precedence than the arithmetic operators.



                                                                                              (%)i=sum.map(^i) is the same length as i%l=sum.map(^i)l. Making it more point-free doesn't help. Defining it like g i=... loses bytes when we call it. Although % works for any list but we only call it with the problem input list, there's no byte loss in calling it with argument l every time because a two-argument call i%l is no longer than a one-argument one g i.






                                                                                              share|improve this answer





















                                                                                              • We do have $LaTeX$ here:)
                                                                                                – flawr
                                                                                                Dec 16 '18 at 9:59










                                                                                              • I really like the % idea! It looks just like the discrete version of the statistical moments.
                                                                                                – flawr
                                                                                                Dec 16 '18 at 10:02














                                                                                              1












                                                                                              1








                                                                                              1







                                                                                              Haskell, 59 bytes





                                                                                              (%)i=sum.map(^i)
                                                                                              f l=[(0%l*y-1%l)/sqrt(2%l*0%l-1%l^2)|y<-l]


                                                                                              Try it online!



                                                                                              Doesn't use libraries.



                                                                                              The helper function % computes the sum of ith powers of a list, which lets us get three useful values.





                                                                                              • 0%l is the length of l (call this n)


                                                                                              • 1%l is the sum of l (call this s)


                                                                                              • 2%l is the sum of squares of l (call this m)


                                                                                              We can express the z-score of an element y as



                                                                                              (n*y-s)/sqrt(n*v-s^2)


                                                                                              (This is the expression (y-s/n)/sqrt(v/n-(s/n)^2) simplified a bit by multiplying the top and bottom by n.)



                                                                                              We can insert the expressions 0%l, 1%l, 2%l without parens because the % we define has higher precedence than the arithmetic operators.



                                                                                              (%)i=sum.map(^i) is the same length as i%l=sum.map(^i)l. Making it more point-free doesn't help. Defining it like g i=... loses bytes when we call it. Although % works for any list but we only call it with the problem input list, there's no byte loss in calling it with argument l every time because a two-argument call i%l is no longer than a one-argument one g i.






                                                                                              share|improve this answer













                                                                                              Haskell, 59 bytes





                                                                                              (%)i=sum.map(^i)
                                                                                              f l=[(0%l*y-1%l)/sqrt(2%l*0%l-1%l^2)|y<-l]


                                                                                              Try it online!



                                                                                              Doesn't use libraries.



                                                                                              The helper function % computes the sum of ith powers of a list, which lets us get three useful values.





                                                                                              • 0%l is the length of l (call this n)


                                                                                              • 1%l is the sum of l (call this s)


                                                                                              • 2%l is the sum of squares of l (call this m)


                                                                                              We can express the z-score of an element y as



                                                                                              (n*y-s)/sqrt(n*v-s^2)


                                                                                              (This is the expression (y-s/n)/sqrt(v/n-(s/n)^2) simplified a bit by multiplying the top and bottom by n.)



                                                                                              We can insert the expressions 0%l, 1%l, 2%l without parens because the % we define has higher precedence than the arithmetic operators.



                                                                                              (%)i=sum.map(^i) is the same length as i%l=sum.map(^i)l. Making it more point-free doesn't help. Defining it like g i=... loses bytes when we call it. Although % works for any list but we only call it with the problem input list, there's no byte loss in calling it with argument l every time because a two-argument call i%l is no longer than a one-argument one g i.







                                                                                              share|improve this answer












                                                                                              share|improve this answer



                                                                                              share|improve this answer










                                                                                              answered Dec 16 '18 at 7:24









                                                                                              xnorxnor

                                                                                              89.8k18184439




                                                                                              89.8k18184439












                                                                                              • We do have $LaTeX$ here:)
                                                                                                – flawr
                                                                                                Dec 16 '18 at 9:59










                                                                                              • I really like the % idea! It looks just like the discrete version of the statistical moments.
                                                                                                – flawr
                                                                                                Dec 16 '18 at 10:02


















                                                                                              • We do have $LaTeX$ here:)
                                                                                                – flawr
                                                                                                Dec 16 '18 at 9:59










                                                                                              • I really like the % idea! It looks just like the discrete version of the statistical moments.
                                                                                                – flawr
                                                                                                Dec 16 '18 at 10:02
















                                                                                              We do have $LaTeX$ here:)
                                                                                              – flawr
                                                                                              Dec 16 '18 at 9:59




                                                                                              We do have $LaTeX$ here:)
                                                                                              – flawr
                                                                                              Dec 16 '18 at 9:59












                                                                                              I really like the % idea! It looks just like the discrete version of the statistical moments.
                                                                                              – flawr
                                                                                              Dec 16 '18 at 10:02




                                                                                              I really like the % idea! It looks just like the discrete version of the statistical moments.
                                                                                              – flawr
                                                                                              Dec 16 '18 at 10:02











                                                                                              1















                                                                                              K (oK), 33 23 bytes



                                                                                              -10 bytes thanks to ngn!



                                                                                              {t%%(+/t*t:x-/x%#x)%#x}


                                                                                              Try it online!



                                                                                              First attempt at coding (I don't dare to name it "golfing") in K. I'm pretty sure it can be done much better (too many variable names here...)






                                                                                              share|improve this answer



















                                                                                              • 1




                                                                                                nice! you can replace the initial (x-m) with t (tio)
                                                                                                – ngn
                                                                                                Dec 16 '18 at 9:53






                                                                                              • 1




                                                                                                the inner { } is unnecessary - its implicit parameter name is x and it has been passed an x as argument (tio)
                                                                                                – ngn
                                                                                                Dec 16 '18 at 9:56








                                                                                              • 1




                                                                                                another -1 byte by replacing x-+/x with x-/x. the left argument to -/ serves as initial value for the reduction (tio)
                                                                                                – ngn
                                                                                                Dec 16 '18 at 10:08












                                                                                              • @ngn Thank you! Now I see that the first 2 golfs are obvious; the last one is beyond my current level :)
                                                                                                – Galen Ivanov
                                                                                                Dec 16 '18 at 10:14
















                                                                                              1















                                                                                              K (oK), 33 23 bytes



                                                                                              -10 bytes thanks to ngn!



                                                                                              {t%%(+/t*t:x-/x%#x)%#x}


                                                                                              Try it online!



                                                                                              First attempt at coding (I don't dare to name it "golfing") in K. I'm pretty sure it can be done much better (too many variable names here...)






                                                                                              share|improve this answer



















                                                                                              • 1




                                                                                                nice! you can replace the initial (x-m) with t (tio)
                                                                                                – ngn
                                                                                                Dec 16 '18 at 9:53






                                                                                              • 1




                                                                                                the inner { } is unnecessary - its implicit parameter name is x and it has been passed an x as argument (tio)
                                                                                                – ngn
                                                                                                Dec 16 '18 at 9:56








                                                                                              • 1




                                                                                                another -1 byte by replacing x-+/x with x-/x. the left argument to -/ serves as initial value for the reduction (tio)
                                                                                                – ngn
                                                                                                Dec 16 '18 at 10:08












                                                                                              • @ngn Thank you! Now I see that the first 2 golfs are obvious; the last one is beyond my current level :)
                                                                                                – Galen Ivanov
                                                                                                Dec 16 '18 at 10:14














                                                                                              1












                                                                                              1








                                                                                              1







                                                                                              K (oK), 33 23 bytes



                                                                                              -10 bytes thanks to ngn!



                                                                                              {t%%(+/t*t:x-/x%#x)%#x}


                                                                                              Try it online!



                                                                                              First attempt at coding (I don't dare to name it "golfing") in K. I'm pretty sure it can be done much better (too many variable names here...)






                                                                                              share|improve this answer















                                                                                              K (oK), 33 23 bytes



                                                                                              -10 bytes thanks to ngn!



                                                                                              {t%%(+/t*t:x-/x%#x)%#x}


                                                                                              Try it online!



                                                                                              First attempt at coding (I don't dare to name it "golfing") in K. I'm pretty sure it can be done much better (too many variable names here...)







                                                                                              share|improve this answer














                                                                                              share|improve this answer



                                                                                              share|improve this answer








                                                                                              edited Dec 16 '18 at 10:15

























                                                                                              answered Dec 15 '18 at 10:33









                                                                                              Galen IvanovGalen Ivanov

                                                                                              6,41711032




                                                                                              6,41711032








                                                                                              • 1




                                                                                                nice! you can replace the initial (x-m) with t (tio)
                                                                                                – ngn
                                                                                                Dec 16 '18 at 9:53






                                                                                              • 1




                                                                                                the inner { } is unnecessary - its implicit parameter name is x and it has been passed an x as argument (tio)
                                                                                                – ngn
                                                                                                Dec 16 '18 at 9:56








                                                                                              • 1




                                                                                                another -1 byte by replacing x-+/x with x-/x. the left argument to -/ serves as initial value for the reduction (tio)
                                                                                                – ngn
                                                                                                Dec 16 '18 at 10:08












                                                                                              • @ngn Thank you! Now I see that the first 2 golfs are obvious; the last one is beyond my current level :)
                                                                                                – Galen Ivanov
                                                                                                Dec 16 '18 at 10:14














                                                                                              • 1




                                                                                                nice! you can replace the initial (x-m) with t (tio)
                                                                                                – ngn
                                                                                                Dec 16 '18 at 9:53






                                                                                              • 1




                                                                                                the inner { } is unnecessary - its implicit parameter name is x and it has been passed an x as argument (tio)
                                                                                                – ngn
                                                                                                Dec 16 '18 at 9:56








                                                                                              • 1




                                                                                                another -1 byte by replacing x-+/x with x-/x. the left argument to -/ serves as initial value for the reduction (tio)
                                                                                                – ngn
                                                                                                Dec 16 '18 at 10:08












                                                                                              • @ngn Thank you! Now I see that the first 2 golfs are obvious; the last one is beyond my current level :)
                                                                                                – Galen Ivanov
                                                                                                Dec 16 '18 at 10:14








                                                                                              1




                                                                                              1




                                                                                              nice! you can replace the initial (x-m) with t (tio)
                                                                                              – ngn
                                                                                              Dec 16 '18 at 9:53




                                                                                              nice! you can replace the initial (x-m) with t (tio)
                                                                                              – ngn
                                                                                              Dec 16 '18 at 9:53




                                                                                              1




                                                                                              1




                                                                                              the inner { } is unnecessary - its implicit parameter name is x and it has been passed an x as argument (tio)
                                                                                              – ngn
                                                                                              Dec 16 '18 at 9:56






                                                                                              the inner { } is unnecessary - its implicit parameter name is x and it has been passed an x as argument (tio)
                                                                                              – ngn
                                                                                              Dec 16 '18 at 9:56






                                                                                              1




                                                                                              1




                                                                                              another -1 byte by replacing x-+/x with x-/x. the left argument to -/ serves as initial value for the reduction (tio)
                                                                                              – ngn
                                                                                              Dec 16 '18 at 10:08






                                                                                              another -1 byte by replacing x-+/x with x-/x. the left argument to -/ serves as initial value for the reduction (tio)
                                                                                              – ngn
                                                                                              Dec 16 '18 at 10:08














                                                                                              @ngn Thank you! Now I see that the first 2 golfs are obvious; the last one is beyond my current level :)
                                                                                              – Galen Ivanov
                                                                                              Dec 16 '18 at 10:14




                                                                                              @ngn Thank you! Now I see that the first 2 golfs are obvious; the last one is beyond my current level :)
                                                                                              – Galen Ivanov
                                                                                              Dec 16 '18 at 10:14











                                                                                              1














                                                                                              MATLAB, 26 bytes



                                                                                              Trivial-ish, std(,1) for using population standard deviation



                                                                                              f=@(x)(x-mean(x))/std(x,1)





                                                                                              share|improve this answer


























                                                                                                1














                                                                                                MATLAB, 26 bytes



                                                                                                Trivial-ish, std(,1) for using population standard deviation



                                                                                                f=@(x)(x-mean(x))/std(x,1)





                                                                                                share|improve this answer
























                                                                                                  1












                                                                                                  1








                                                                                                  1






                                                                                                  MATLAB, 26 bytes



                                                                                                  Trivial-ish, std(,1) for using population standard deviation



                                                                                                  f=@(x)(x-mean(x))/std(x,1)





                                                                                                  share|improve this answer












                                                                                                  MATLAB, 26 bytes



                                                                                                  Trivial-ish, std(,1) for using population standard deviation



                                                                                                  f=@(x)(x-mean(x))/std(x,1)






                                                                                                  share|improve this answer












                                                                                                  share|improve this answer



                                                                                                  share|improve this answer










                                                                                                  answered Dec 16 '18 at 15:37









                                                                                                  aaaaaaaaaaaa

                                                                                                  3116




                                                                                                  3116























                                                                                                      1














                                                                                                      TI-Basic (83 series), 14 11 bytes



                                                                                                      Ans-mean(Ans
                                                                                                      Ans/√(mean(Ans²


                                                                                                      Takes input in Ans. For example, if you type the above into prgmSTANDARD, then {1,2,3}:prgmSTANDARD will return {-1.224744871,0.0,1.224744871}.



                                                                                                      Previously, I tried using the 1-Var Stats command, which stores the population standard deviation in σx, but it's less trouble to compute it manually.






                                                                                                      share|improve this answer




























                                                                                                        1














                                                                                                        TI-Basic (83 series), 14 11 bytes



                                                                                                        Ans-mean(Ans
                                                                                                        Ans/√(mean(Ans²


                                                                                                        Takes input in Ans. For example, if you type the above into prgmSTANDARD, then {1,2,3}:prgmSTANDARD will return {-1.224744871,0.0,1.224744871}.



                                                                                                        Previously, I tried using the 1-Var Stats command, which stores the population standard deviation in σx, but it's less trouble to compute it manually.






                                                                                                        share|improve this answer


























                                                                                                          1












                                                                                                          1








                                                                                                          1






                                                                                                          TI-Basic (83 series), 14 11 bytes



                                                                                                          Ans-mean(Ans
                                                                                                          Ans/√(mean(Ans²


                                                                                                          Takes input in Ans. For example, if you type the above into prgmSTANDARD, then {1,2,3}:prgmSTANDARD will return {-1.224744871,0.0,1.224744871}.



                                                                                                          Previously, I tried using the 1-Var Stats command, which stores the population standard deviation in σx, but it's less trouble to compute it manually.






                                                                                                          share|improve this answer














                                                                                                          TI-Basic (83 series), 14 11 bytes



                                                                                                          Ans-mean(Ans
                                                                                                          Ans/√(mean(Ans²


                                                                                                          Takes input in Ans. For example, if you type the above into prgmSTANDARD, then {1,2,3}:prgmSTANDARD will return {-1.224744871,0.0,1.224744871}.



                                                                                                          Previously, I tried using the 1-Var Stats command, which stores the population standard deviation in σx, but it's less trouble to compute it manually.







                                                                                                          share|improve this answer














                                                                                                          share|improve this answer



                                                                                                          share|improve this answer








                                                                                                          edited Dec 16 '18 at 21:31

























                                                                                                          answered Dec 16 '18 at 21:25









                                                                                                          Misha LavrovMisha Lavrov

                                                                                                          4,211424




                                                                                                          4,211424























                                                                                                              1















                                                                                                              05AB1E, 9 bytes



                                                                                                              ÅA-DnÅAt/


                                                                                                              Port of @Arnauld's JavaScript answer, so make sure to upvote him!



                                                                                                              Try it online or verify all test cases.



                                                                                                              Explanation:





                                                                                                              ÅA          # Calculate the mean of the (implicit) input
                                                                                                              # i.e. [-3,1,4,1,5] → 1.6
                                                                                                              - # Subtract it from each value in the (implicit) input
                                                                                                              # i.e. [-3,1,4,1,5] and 1.6 → [-4.6,-0.6,2.4,-0.6,3.4]
                                                                                                              D # Duplicate that list
                                                                                                              n # Take the square of each
                                                                                                              # i.e. [-4.6,-0.6,2.4,-0.6,3.4] → [21.16,0.36,5.76,0.36,11.56]
                                                                                                              ÅA # Pop and calculate the mean of that list
                                                                                                              # i.e. [21.16,0.36,5.76,0.36,11.56] → 7.84
                                                                                                              t # Take the square-root of that
                                                                                                              # i.e. 7.84 → 2.8
                                                                                                              / # And divide each value in the duplicated list with it (and output implicitly)
                                                                                                              # i.e. [-4.6,-0.6,2.4,-0.6,3.4] and 2.8 → [-1.6428571428571428,
                                                                                                              # -0.21428571428571433,0.8571428571428572,-0.21428571428571433,1.2142857142857144]





                                                                                                              share|improve this answer


























                                                                                                                1















                                                                                                                05AB1E, 9 bytes



                                                                                                                ÅA-DnÅAt/


                                                                                                                Port of @Arnauld's JavaScript answer, so make sure to upvote him!



                                                                                                                Try it online or verify all test cases.



                                                                                                                Explanation:





                                                                                                                ÅA          # Calculate the mean of the (implicit) input
                                                                                                                # i.e. [-3,1,4,1,5] → 1.6
                                                                                                                - # Subtract it from each value in the (implicit) input
                                                                                                                # i.e. [-3,1,4,1,5] and 1.6 → [-4.6,-0.6,2.4,-0.6,3.4]
                                                                                                                D # Duplicate that list
                                                                                                                n # Take the square of each
                                                                                                                # i.e. [-4.6,-0.6,2.4,-0.6,3.4] → [21.16,0.36,5.76,0.36,11.56]
                                                                                                                ÅA # Pop and calculate the mean of that list
                                                                                                                # i.e. [21.16,0.36,5.76,0.36,11.56] → 7.84
                                                                                                                t # Take the square-root of that
                                                                                                                # i.e. 7.84 → 2.8
                                                                                                                / # And divide each value in the duplicated list with it (and output implicitly)
                                                                                                                # i.e. [-4.6,-0.6,2.4,-0.6,3.4] and 2.8 → [-1.6428571428571428,
                                                                                                                # -0.21428571428571433,0.8571428571428572,-0.21428571428571433,1.2142857142857144]





                                                                                                                share|improve this answer
























                                                                                                                  1












                                                                                                                  1








                                                                                                                  1







                                                                                                                  05AB1E, 9 bytes



                                                                                                                  ÅA-DnÅAt/


                                                                                                                  Port of @Arnauld's JavaScript answer, so make sure to upvote him!



                                                                                                                  Try it online or verify all test cases.



                                                                                                                  Explanation:





                                                                                                                  ÅA          # Calculate the mean of the (implicit) input
                                                                                                                  # i.e. [-3,1,4,1,5] → 1.6
                                                                                                                  - # Subtract it from each value in the (implicit) input
                                                                                                                  # i.e. [-3,1,4,1,5] and 1.6 → [-4.6,-0.6,2.4,-0.6,3.4]
                                                                                                                  D # Duplicate that list
                                                                                                                  n # Take the square of each
                                                                                                                  # i.e. [-4.6,-0.6,2.4,-0.6,3.4] → [21.16,0.36,5.76,0.36,11.56]
                                                                                                                  ÅA # Pop and calculate the mean of that list
                                                                                                                  # i.e. [21.16,0.36,5.76,0.36,11.56] → 7.84
                                                                                                                  t # Take the square-root of that
                                                                                                                  # i.e. 7.84 → 2.8
                                                                                                                  / # And divide each value in the duplicated list with it (and output implicitly)
                                                                                                                  # i.e. [-4.6,-0.6,2.4,-0.6,3.4] and 2.8 → [-1.6428571428571428,
                                                                                                                  # -0.21428571428571433,0.8571428571428572,-0.21428571428571433,1.2142857142857144]





                                                                                                                  share|improve this answer













                                                                                                                  05AB1E, 9 bytes



                                                                                                                  ÅA-DnÅAt/


                                                                                                                  Port of @Arnauld's JavaScript answer, so make sure to upvote him!



                                                                                                                  Try it online or verify all test cases.



                                                                                                                  Explanation:





                                                                                                                  ÅA          # Calculate the mean of the (implicit) input
                                                                                                                  # i.e. [-3,1,4,1,5] → 1.6
                                                                                                                  - # Subtract it from each value in the (implicit) input
                                                                                                                  # i.e. [-3,1,4,1,5] and 1.6 → [-4.6,-0.6,2.4,-0.6,3.4]
                                                                                                                  D # Duplicate that list
                                                                                                                  n # Take the square of each
                                                                                                                  # i.e. [-4.6,-0.6,2.4,-0.6,3.4] → [21.16,0.36,5.76,0.36,11.56]
                                                                                                                  ÅA # Pop and calculate the mean of that list
                                                                                                                  # i.e. [21.16,0.36,5.76,0.36,11.56] → 7.84
                                                                                                                  t # Take the square-root of that
                                                                                                                  # i.e. 7.84 → 2.8
                                                                                                                  / # And divide each value in the duplicated list with it (and output implicitly)
                                                                                                                  # i.e. [-4.6,-0.6,2.4,-0.6,3.4] and 2.8 → [-1.6428571428571428,
                                                                                                                  # -0.21428571428571433,0.8571428571428572,-0.21428571428571433,1.2142857142857144]






                                                                                                                  share|improve this answer












                                                                                                                  share|improve this answer



                                                                                                                  share|improve this answer










                                                                                                                  answered Dec 17 '18 at 8:51









                                                                                                                  Kevin CruijssenKevin Cruijssen

                                                                                                                  36k554189




                                                                                                                  36k554189























                                                                                                                      0















                                                                                                                      Jelly, 10 bytes



                                                                                                                      _Æm÷²Æm½Ɗ$


                                                                                                                      Try it online!






                                                                                                                      share|improve this answer


























                                                                                                                        0















                                                                                                                        Jelly, 10 bytes



                                                                                                                        _Æm÷²Æm½Ɗ$


                                                                                                                        Try it online!






                                                                                                                        share|improve this answer
























                                                                                                                          0












                                                                                                                          0








                                                                                                                          0







                                                                                                                          Jelly, 10 bytes



                                                                                                                          _Æm÷²Æm½Ɗ$


                                                                                                                          Try it online!






                                                                                                                          share|improve this answer













                                                                                                                          Jelly, 10 bytes



                                                                                                                          _Æm÷²Æm½Ɗ$


                                                                                                                          Try it online!







                                                                                                                          share|improve this answer












                                                                                                                          share|improve this answer



                                                                                                                          share|improve this answer










                                                                                                                          answered Dec 14 '18 at 18:57









                                                                                                                          Erik the OutgolferErik the Outgolfer

                                                                                                                          31.4k429103




                                                                                                                          31.4k429103























                                                                                                                              0














                                                                                                                              Pyth, 21 19 bytes



                                                                                                                              mc-dJ.OQ@.Om^-Jk2Q2


                                                                                                                              Try it online here.



                                                                                                                              mc-dJ.OQ@.Om^-Jk2Q2Q   Implicit: Q=eval(input())
                                                                                                                              Trailing Q inferred
                                                                                                                              J.OQ Take the average of Q, store the result in J
                                                                                                                              m Q Map the elements of Q, as k, using:
                                                                                                                              -Jk Difference between J and k
                                                                                                                              ^ 2 Square it
                                                                                                                              .O Find the average of the result of the map
                                                                                                                              @ 2 Square root it
                                                                                                                              - this is the standard deviation of Q
                                                                                                                              m Q Map elements of Q, as d, using:
                                                                                                                              -dJ d - J
                                                                                                                              c Float division by the standard deviation
                                                                                                                              Implicit print result of map


                                                                                                                              Edit: after seeing Kevin's answer, changed to use the average builtin for the inner results. Previous answer: mc-dJ.OQ@csm^-Jk2QlQ2






                                                                                                                              share|improve this answer




























                                                                                                                                0














                                                                                                                                Pyth, 21 19 bytes



                                                                                                                                mc-dJ.OQ@.Om^-Jk2Q2


                                                                                                                                Try it online here.



                                                                                                                                mc-dJ.OQ@.Om^-Jk2Q2Q   Implicit: Q=eval(input())
                                                                                                                                Trailing Q inferred
                                                                                                                                J.OQ Take the average of Q, store the result in J
                                                                                                                                m Q Map the elements of Q, as k, using:
                                                                                                                                -Jk Difference between J and k
                                                                                                                                ^ 2 Square it
                                                                                                                                .O Find the average of the result of the map
                                                                                                                                @ 2 Square root it
                                                                                                                                - this is the standard deviation of Q
                                                                                                                                m Q Map elements of Q, as d, using:
                                                                                                                                -dJ d - J
                                                                                                                                c Float division by the standard deviation
                                                                                                                                Implicit print result of map


                                                                                                                                Edit: after seeing Kevin's answer, changed to use the average builtin for the inner results. Previous answer: mc-dJ.OQ@csm^-Jk2QlQ2






                                                                                                                                share|improve this answer


























                                                                                                                                  0












                                                                                                                                  0








                                                                                                                                  0






                                                                                                                                  Pyth, 21 19 bytes



                                                                                                                                  mc-dJ.OQ@.Om^-Jk2Q2


                                                                                                                                  Try it online here.



                                                                                                                                  mc-dJ.OQ@.Om^-Jk2Q2Q   Implicit: Q=eval(input())
                                                                                                                                  Trailing Q inferred
                                                                                                                                  J.OQ Take the average of Q, store the result in J
                                                                                                                                  m Q Map the elements of Q, as k, using:
                                                                                                                                  -Jk Difference between J and k
                                                                                                                                  ^ 2 Square it
                                                                                                                                  .O Find the average of the result of the map
                                                                                                                                  @ 2 Square root it
                                                                                                                                  - this is the standard deviation of Q
                                                                                                                                  m Q Map elements of Q, as d, using:
                                                                                                                                  -dJ d - J
                                                                                                                                  c Float division by the standard deviation
                                                                                                                                  Implicit print result of map


                                                                                                                                  Edit: after seeing Kevin's answer, changed to use the average builtin for the inner results. Previous answer: mc-dJ.OQ@csm^-Jk2QlQ2






                                                                                                                                  share|improve this answer














                                                                                                                                  Pyth, 21 19 bytes



                                                                                                                                  mc-dJ.OQ@.Om^-Jk2Q2


                                                                                                                                  Try it online here.



                                                                                                                                  mc-dJ.OQ@.Om^-Jk2Q2Q   Implicit: Q=eval(input())
                                                                                                                                  Trailing Q inferred
                                                                                                                                  J.OQ Take the average of Q, store the result in J
                                                                                                                                  m Q Map the elements of Q, as k, using:
                                                                                                                                  -Jk Difference between J and k
                                                                                                                                  ^ 2 Square it
                                                                                                                                  .O Find the average of the result of the map
                                                                                                                                  @ 2 Square root it
                                                                                                                                  - this is the standard deviation of Q
                                                                                                                                  m Q Map elements of Q, as d, using:
                                                                                                                                  -dJ d - J
                                                                                                                                  c Float division by the standard deviation
                                                                                                                                  Implicit print result of map


                                                                                                                                  Edit: after seeing Kevin's answer, changed to use the average builtin for the inner results. Previous answer: mc-dJ.OQ@csm^-Jk2QlQ2







                                                                                                                                  share|improve this answer














                                                                                                                                  share|improve this answer



                                                                                                                                  share|improve this answer








                                                                                                                                  edited Dec 17 '18 at 9:06

























                                                                                                                                  answered Dec 16 '18 at 11:23









                                                                                                                                  SokSok

                                                                                                                                  3,597722




                                                                                                                                  3,597722























                                                                                                                                      0















                                                                                                                                      SNOBOL4 (CSNOBOL4), 229 bytes



                                                                                                                                      	DEFINE('Z(A)')
                                                                                                                                      Z X =X + 1
                                                                                                                                      M =M + A<X> :S(Z)
                                                                                                                                      N =X - 1.
                                                                                                                                      M =M / N
                                                                                                                                      D X =GT(X) X - 1 :F(S)
                                                                                                                                      A<X> =A<X> - M :(D)
                                                                                                                                      S X =LT(X,N) X + 1 :F(Y)
                                                                                                                                      S =S + A<X> ^ 2 / N :(S)
                                                                                                                                      Y S =S ^ 0.5
                                                                                                                                      N A<X> =A<X> / S
                                                                                                                                      X =GT(X) X - 1 :S(N)
                                                                                                                                      Z =A :(RETURN)


                                                                                                                                      Try it online!



                                                                                                                                      Link is to a functional version of the code which constructs an array from STDIN given its length and then its elements, then runs the function Z on that, and finally prints out the values.



                                                                                                                                      Defines a function Z which returns an array.



                                                                                                                                      The 1. on line 4 is necessary to do the floating point arithmetic properly.






                                                                                                                                      share|improve this answer


























                                                                                                                                        0















                                                                                                                                        SNOBOL4 (CSNOBOL4), 229 bytes



                                                                                                                                        	DEFINE('Z(A)')
                                                                                                                                        Z X =X + 1
                                                                                                                                        M =M + A<X> :S(Z)
                                                                                                                                        N =X - 1.
                                                                                                                                        M =M / N
                                                                                                                                        D X =GT(X) X - 1 :F(S)
                                                                                                                                        A<X> =A<X> - M :(D)
                                                                                                                                        S X =LT(X,N) X + 1 :F(Y)
                                                                                                                                        S =S + A<X> ^ 2 / N :(S)
                                                                                                                                        Y S =S ^ 0.5
                                                                                                                                        N A<X> =A<X> / S
                                                                                                                                        X =GT(X) X - 1 :S(N)
                                                                                                                                        Z =A :(RETURN)


                                                                                                                                        Try it online!



                                                                                                                                        Link is to a functional version of the code which constructs an array from STDIN given its length and then its elements, then runs the function Z on that, and finally prints out the values.



                                                                                                                                        Defines a function Z which returns an array.



                                                                                                                                        The 1. on line 4 is necessary to do the floating point arithmetic properly.






                                                                                                                                        share|improve this answer
























                                                                                                                                          0












                                                                                                                                          0








                                                                                                                                          0







                                                                                                                                          SNOBOL4 (CSNOBOL4), 229 bytes



                                                                                                                                          	DEFINE('Z(A)')
                                                                                                                                          Z X =X + 1
                                                                                                                                          M =M + A<X> :S(Z)
                                                                                                                                          N =X - 1.
                                                                                                                                          M =M / N
                                                                                                                                          D X =GT(X) X - 1 :F(S)
                                                                                                                                          A<X> =A<X> - M :(D)
                                                                                                                                          S X =LT(X,N) X + 1 :F(Y)
                                                                                                                                          S =S + A<X> ^ 2 / N :(S)
                                                                                                                                          Y S =S ^ 0.5
                                                                                                                                          N A<X> =A<X> / S
                                                                                                                                          X =GT(X) X - 1 :S(N)
                                                                                                                                          Z =A :(RETURN)


                                                                                                                                          Try it online!



                                                                                                                                          Link is to a functional version of the code which constructs an array from STDIN given its length and then its elements, then runs the function Z on that, and finally prints out the values.



                                                                                                                                          Defines a function Z which returns an array.



                                                                                                                                          The 1. on line 4 is necessary to do the floating point arithmetic properly.






                                                                                                                                          share|improve this answer













                                                                                                                                          SNOBOL4 (CSNOBOL4), 229 bytes



                                                                                                                                          	DEFINE('Z(A)')
                                                                                                                                          Z X =X + 1
                                                                                                                                          M =M + A<X> :S(Z)
                                                                                                                                          N =X - 1.
                                                                                                                                          M =M / N
                                                                                                                                          D X =GT(X) X - 1 :F(S)
                                                                                                                                          A<X> =A<X> - M :(D)
                                                                                                                                          S X =LT(X,N) X + 1 :F(Y)
                                                                                                                                          S =S + A<X> ^ 2 / N :(S)
                                                                                                                                          Y S =S ^ 0.5
                                                                                                                                          N A<X> =A<X> / S
                                                                                                                                          X =GT(X) X - 1 :S(N)
                                                                                                                                          Z =A :(RETURN)


                                                                                                                                          Try it online!



                                                                                                                                          Link is to a functional version of the code which constructs an array from STDIN given its length and then its elements, then runs the function Z on that, and finally prints out the values.



                                                                                                                                          Defines a function Z which returns an array.



                                                                                                                                          The 1. on line 4 is necessary to do the floating point arithmetic properly.







                                                                                                                                          share|improve this answer












                                                                                                                                          share|improve this answer



                                                                                                                                          share|improve this answer










                                                                                                                                          answered Dec 17 '18 at 15:29









                                                                                                                                          GiuseppeGiuseppe

                                                                                                                                          16.6k31052




                                                                                                                                          16.6k31052























                                                                                                                                              0















                                                                                                                                              Julia 0.7, 37 bytes





                                                                                                                                              a->(a-mean(a))/std(a,corrected=false)


                                                                                                                                              Try it online!






                                                                                                                                              share|improve this answer


























                                                                                                                                                0















                                                                                                                                                Julia 0.7, 37 bytes





                                                                                                                                                a->(a-mean(a))/std(a,corrected=false)


                                                                                                                                                Try it online!






                                                                                                                                                share|improve this answer
























                                                                                                                                                  0












                                                                                                                                                  0








                                                                                                                                                  0







                                                                                                                                                  Julia 0.7, 37 bytes





                                                                                                                                                  a->(a-mean(a))/std(a,corrected=false)


                                                                                                                                                  Try it online!






                                                                                                                                                  share|improve this answer













                                                                                                                                                  Julia 0.7, 37 bytes





                                                                                                                                                  a->(a-mean(a))/std(a,corrected=false)


                                                                                                                                                  Try it online!







                                                                                                                                                  share|improve this answer












                                                                                                                                                  share|improve this answer



                                                                                                                                                  share|improve this answer










                                                                                                                                                  answered Dec 19 '18 at 10:01









                                                                                                                                                  Kirill L.Kirill L.

                                                                                                                                                  3,6751319




                                                                                                                                                  3,6751319























                                                                                                                                                      0















                                                                                                                                                      Charcoal, 25 19 bytes



                                                                                                                                                      ≧⁻∕ΣθLθθI∕θ₂∕ΣXθ²Lθ


                                                                                                                                                      Try it online! Link is to verbose version of code. Explanation:



                                                                                                                                                             θ    Input array
                                                                                                                                                      ≧ Update each element
                                                                                                                                                      ⁻ Subtract
                                                                                                                                                      Σ Sum of
                                                                                                                                                      θ Input array
                                                                                                                                                      ∕ Divided by
                                                                                                                                                      L Length of
                                                                                                                                                      θ Input array


                                                                                                                                                      Calculate $mu$ and vectorised subtract it from each $x_i$.



                                                                                                                                                        θ         Updated array
                                                                                                                                                      ∕ Vectorised divided by
                                                                                                                                                      ₂ Square root of
                                                                                                                                                      Σ Sum of
                                                                                                                                                      θ Updated array
                                                                                                                                                      X Vectorised to power
                                                                                                                                                      ² Literal 2
                                                                                                                                                      ∕ Divided by
                                                                                                                                                      L Length of
                                                                                                                                                      θ Array
                                                                                                                                                      I Cast to string
                                                                                                                                                      Implicitly print each element on its own line.


                                                                                                                                                      Calculate $sigma$, vectorised divide each $x_i$ by it, and output the result.



                                                                                                                                                      Edit: Saved 6 bytes thanks to @ASCII-only for a) using SquareRoot() instead of Power(0.5) b) fixing vectorised Divide() (it was doing IntDivide() instead) c) making Power() vectorise.






                                                                                                                                                      share|improve this answer























                                                                                                                                                      • crossed out 25 = no bytes? :P (Also, you haven't updated the TIO link yet)
                                                                                                                                                        – ASCII-only
                                                                                                                                                        Dec 25 '18 at 10:59












                                                                                                                                                      • @ASCII-only Oops, thanks!
                                                                                                                                                        – Neil
                                                                                                                                                        Dec 25 '18 at 14:32
















                                                                                                                                                      0















                                                                                                                                                      Charcoal, 25 19 bytes



                                                                                                                                                      ≧⁻∕ΣθLθθI∕θ₂∕ΣXθ²Lθ


                                                                                                                                                      Try it online! Link is to verbose version of code. Explanation:



                                                                                                                                                             θ    Input array
                                                                                                                                                      ≧ Update each element
                                                                                                                                                      ⁻ Subtract
                                                                                                                                                      Σ Sum of
                                                                                                                                                      θ Input array
                                                                                                                                                      ∕ Divided by
                                                                                                                                                      L Length of
                                                                                                                                                      θ Input array


                                                                                                                                                      Calculate $mu$ and vectorised subtract it from each $x_i$.



                                                                                                                                                        θ         Updated array
                                                                                                                                                      ∕ Vectorised divided by
                                                                                                                                                      ₂ Square root of
                                                                                                                                                      Σ Sum of
                                                                                                                                                      θ Updated array
                                                                                                                                                      X Vectorised to power
                                                                                                                                                      ² Literal 2
                                                                                                                                                      ∕ Divided by
                                                                                                                                                      L Length of
                                                                                                                                                      θ Array
                                                                                                                                                      I Cast to string
                                                                                                                                                      Implicitly print each element on its own line.


                                                                                                                                                      Calculate $sigma$, vectorised divide each $x_i$ by it, and output the result.



                                                                                                                                                      Edit: Saved 6 bytes thanks to @ASCII-only for a) using SquareRoot() instead of Power(0.5) b) fixing vectorised Divide() (it was doing IntDivide() instead) c) making Power() vectorise.






                                                                                                                                                      share|improve this answer























                                                                                                                                                      • crossed out 25 = no bytes? :P (Also, you haven't updated the TIO link yet)
                                                                                                                                                        – ASCII-only
                                                                                                                                                        Dec 25 '18 at 10:59












                                                                                                                                                      • @ASCII-only Oops, thanks!
                                                                                                                                                        – Neil
                                                                                                                                                        Dec 25 '18 at 14:32














                                                                                                                                                      0












                                                                                                                                                      0








                                                                                                                                                      0







                                                                                                                                                      Charcoal, 25 19 bytes



                                                                                                                                                      ≧⁻∕ΣθLθθI∕θ₂∕ΣXθ²Lθ


                                                                                                                                                      Try it online! Link is to verbose version of code. Explanation:



                                                                                                                                                             θ    Input array
                                                                                                                                                      ≧ Update each element
                                                                                                                                                      ⁻ Subtract
                                                                                                                                                      Σ Sum of
                                                                                                                                                      θ Input array
                                                                                                                                                      ∕ Divided by
                                                                                                                                                      L Length of
                                                                                                                                                      θ Input array


                                                                                                                                                      Calculate $mu$ and vectorised subtract it from each $x_i$.



                                                                                                                                                        θ         Updated array
                                                                                                                                                      ∕ Vectorised divided by
                                                                                                                                                      ₂ Square root of
                                                                                                                                                      Σ Sum of
                                                                                                                                                      θ Updated array
                                                                                                                                                      X Vectorised to power
                                                                                                                                                      ² Literal 2
                                                                                                                                                      ∕ Divided by
                                                                                                                                                      L Length of
                                                                                                                                                      θ Array
                                                                                                                                                      I Cast to string
                                                                                                                                                      Implicitly print each element on its own line.


                                                                                                                                                      Calculate $sigma$, vectorised divide each $x_i$ by it, and output the result.



                                                                                                                                                      Edit: Saved 6 bytes thanks to @ASCII-only for a) using SquareRoot() instead of Power(0.5) b) fixing vectorised Divide() (it was doing IntDivide() instead) c) making Power() vectorise.






                                                                                                                                                      share|improve this answer















                                                                                                                                                      Charcoal, 25 19 bytes



                                                                                                                                                      ≧⁻∕ΣθLθθI∕θ₂∕ΣXθ²Lθ


                                                                                                                                                      Try it online! Link is to verbose version of code. Explanation:



                                                                                                                                                             θ    Input array
                                                                                                                                                      ≧ Update each element
                                                                                                                                                      ⁻ Subtract
                                                                                                                                                      Σ Sum of
                                                                                                                                                      θ Input array
                                                                                                                                                      ∕ Divided by
                                                                                                                                                      L Length of
                                                                                                                                                      θ Input array


                                                                                                                                                      Calculate $mu$ and vectorised subtract it from each $x_i$.



                                                                                                                                                        θ         Updated array
                                                                                                                                                      ∕ Vectorised divided by
                                                                                                                                                      ₂ Square root of
                                                                                                                                                      Σ Sum of
                                                                                                                                                      θ Updated array
                                                                                                                                                      X Vectorised to power
                                                                                                                                                      ² Literal 2
                                                                                                                                                      ∕ Divided by
                                                                                                                                                      L Length of
                                                                                                                                                      θ Array
                                                                                                                                                      I Cast to string
                                                                                                                                                      Implicitly print each element on its own line.


                                                                                                                                                      Calculate $sigma$, vectorised divide each $x_i$ by it, and output the result.



                                                                                                                                                      Edit: Saved 6 bytes thanks to @ASCII-only for a) using SquareRoot() instead of Power(0.5) b) fixing vectorised Divide() (it was doing IntDivide() instead) c) making Power() vectorise.







                                                                                                                                                      share|improve this answer














                                                                                                                                                      share|improve this answer



                                                                                                                                                      share|improve this answer








                                                                                                                                                      edited Dec 25 '18 at 14:32

























                                                                                                                                                      answered Dec 15 '18 at 0:02









                                                                                                                                                      NeilNeil

                                                                                                                                                      79.6k744177




                                                                                                                                                      79.6k744177












                                                                                                                                                      • crossed out 25 = no bytes? :P (Also, you haven't updated the TIO link yet)
                                                                                                                                                        – ASCII-only
                                                                                                                                                        Dec 25 '18 at 10:59












                                                                                                                                                      • @ASCII-only Oops, thanks!
                                                                                                                                                        – Neil
                                                                                                                                                        Dec 25 '18 at 14:32


















                                                                                                                                                      • crossed out 25 = no bytes? :P (Also, you haven't updated the TIO link yet)
                                                                                                                                                        – ASCII-only
                                                                                                                                                        Dec 25 '18 at 10:59












                                                                                                                                                      • @ASCII-only Oops, thanks!
                                                                                                                                                        – Neil
                                                                                                                                                        Dec 25 '18 at 14:32
















                                                                                                                                                      crossed out 25 = no bytes? :P (Also, you haven't updated the TIO link yet)
                                                                                                                                                      – ASCII-only
                                                                                                                                                      Dec 25 '18 at 10:59






                                                                                                                                                      crossed out 25 = no bytes? :P (Also, you haven't updated the TIO link yet)
                                                                                                                                                      – ASCII-only
                                                                                                                                                      Dec 25 '18 at 10:59














                                                                                                                                                      @ASCII-only Oops, thanks!
                                                                                                                                                      – Neil
                                                                                                                                                      Dec 25 '18 at 14:32




                                                                                                                                                      @ASCII-only Oops, thanks!
                                                                                                                                                      – Neil
                                                                                                                                                      Dec 25 '18 at 14:32


















                                                                                                                                                      draft saved

                                                                                                                                                      draft discarded




















































                                                                                                                                                      If this is an answer to a challenge…




                                                                                                                                                      • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                                                                                                                      • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                                                                                                                        Explanations of your answer make it more interesting to read and are very much encouraged.


                                                                                                                                                      • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                                                                                                                                      More generally…




                                                                                                                                                      • …Please make sure to answer the question and provide sufficient detail.


                                                                                                                                                      • …Avoid asking for help, clarification or responding to other answers (use comments instead).






                                                                                                                                                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                                                                                                                      Please pay close attention to the following guidance:


                                                                                                                                                      • Please be sure to answer the question. Provide details and share your research!

                                                                                                                                                      But avoid



                                                                                                                                                      • Asking for help, clarification, or responding to other answers.

                                                                                                                                                      • Making statements based on opinion; back them up with references or personal experience.


                                                                                                                                                      To learn more, see our tips on writing great answers.




                                                                                                                                                      draft saved


                                                                                                                                                      draft discarded














                                                                                                                                                      StackExchange.ready(
                                                                                                                                                      function () {
                                                                                                                                                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f177601%2fstandardize-the-samples-compute-the-z-score%23new-answer', 'question_page');
                                                                                                                                                      }
                                                                                                                                                      );

                                                                                                                                                      Post as a guest















                                                                                                                                                      Required, but never shown





















































                                                                                                                                                      Required, but never shown














                                                                                                                                                      Required, but never shown












                                                                                                                                                      Required, but never shown







                                                                                                                                                      Required, but never shown

































                                                                                                                                                      Required, but never shown














                                                                                                                                                      Required, but never shown












                                                                                                                                                      Required, but never shown







                                                                                                                                                      Required, but never shown







                                                                                                                                                      Popular posts from this blog

                                                                                                                                                      Plaza Victoria

                                                                                                                                                      Puebla de Zaragoza

                                                                                                                                                      Musa