2

In python, I can do this by using python, as in How do I calculate percentiles with python/numpy?

import numpy as np
a = np.array([1,2,3,4,5])
p = np.percentile(a, 50) 

I want to know what is the convenient way in 2018 to calculate percentile in Ruby?

cqcn1991
  • 17,595
  • 41
  • 122
  • 194

1 Answers1

1

That is few lines function, developer can write it by his own in 2018. But you can check descriptive_statistics gem.

require 'descriptive_statistics'
data = [1,2,3,4,5]
data.percentile(50)
Orest Savchak
  • 4,443
  • 1
  • 16
  • 26
  • I've already implemented my own approach, but I always think to put it into some module like numpy would by much better. – cqcn1991 Mar 12 '18 at 12:53