Skip to content

Instantly share code, notes, and snippets.

@josephcc
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save josephcc/e3ea7fcbbc9530038e2e to your computer and use it in GitHub Desktop.

Select an option

Save josephcc/e3ea7fcbbc9530038e2e to your computer and use it in GitHub Desktop.
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