é åã®è¦ç´ ãto_iããå¤ã®å¹³åã»åæ£ã»æ¨æºåå·®ãæ±ããé¢æ°ã§ãã class Array # è¦ç´ ãto_iããå¤ã®å¹³åãç®åºãã def avg inject(0.0){|r,i| r+=i.to_i }/size end # è¦ç´ ãto_iããå¤ã®åæ£ãç®åºãã def variance a = avg inject(0.0){|r,i| r+=(i.to_i-a)**2 }/size end # è¦ç´ ãto_iããå¤ã®æ¨æºåå·®ãç®åºãã def standard_deviation Math.sqrt(variance) end end ãµã³ãã«ã array = [6,4,6,6,6,3,7,2,2,8] puts array.avg puts array.variance puts array.standard_deviation å®è¡çµæã§ãã 5.0 4.0 2.0
{{#tags}}- {{label}}
{{/tags}}