ruby-numo / numo-narray

Ruby/Numo::NArray - New NArray class library
http://ruby-numo.github.io/narray/
BSD 3-Clause "New" or "Revised" License
415 stars 41 forks source link

Adds percentile method #158

Closed ankane closed 4 years ago

ankane commented 4 years ago

Adds percentile method.

a = [[1,2,3],[5,7,11]]
a.percentile(50)
a.percentile(50, axis: 0)
a.percentile(50, axis: 1)

Uses the C = 1 variant for percentile (same as NumPy).

NumPy test code

import numpy as np

x = np.array([[1,2,3],[5,7,11]])
print(np.percentile(x, 0))
print(np.percentile(x, 50))
print(np.percentile(x, 100))
print(np.percentile(x, 0, axis=0))
print(np.percentile(x, 50, axis=0))
print(np.percentile(x, 100, axis=0))
print(np.percentile(x, 0, axis=1))
print(np.percentile(x, 50, axis=1))
print(np.percentile(x, 100, axis=1))
ankane commented 4 years ago

Thanks @masa16!