Last active
August 29, 2015 14:03
-
-
Save josephcc/e3ea7fcbbc9530038e2e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Matrix | |
| def []=(i, j, x) | |
| @rows[i][j] = x | |
| end | |
| end | |
| module Enumerable | |
| def sum | |
| return self.inject(0){|acc,i|acc +i} | |
| end | |
| def mean | |
| return self.sum/self.length.to_f | |
| end | |
| def sample_variance | |
| avg=self.mean | |
| sum=self.inject(0){|acc,i|acc +(i-avg)**2} | |
| return(1/self.length.to_f*sum) | |
| end | |
| def stddev | |
| return Math.sqrt(self.sample_variance) | |
| end | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment