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?

ZK Zhao
  • 19,885
  • 47
  • 132
  • 206

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,529
  • 1
  • 18
  • 27
  • I've already implemented my own approach, but I always think to put it into some module like numpy would by much better. – ZK Zhao Mar 12 '18 at 12:53