@@ -788,6 +788,7 @@ def prctile(x, p = (0.0, 25.0, 50.0, 75.0, 100.0)):
788788 Return the percentiles of x. p can either be a sequence of
789789 percentil values or a scalar. If p is a sequence the i-th element
790790 of the return sequence is the p(i)-th percentile of x
791+
791792 """
792793 x = sort (ravel (x ))
793794 Nx = len (x )
@@ -800,6 +801,27 @@ def prctile(x, p = (0.0, 25.0, 50.0, 75.0, 100.0)):
800801 ind = where (ind >= Nx , Nx - 1 , ind )
801802 return take (x , ind )
802803
804+ def prctile_rank (x , p ):
805+ """
806+ return the for each element in x, return the rank 0..len(p) . Eg
807+ if p=(25, 50, 75), the return value will be a len(x) array with
808+ values in [0,1,2,3] where 0 indicates the value is less than the
809+ 25th percentile, 1 indicates the value is >= the 25th and < 50th
810+ percentile, ... and 3 indicates the value is above the 75th
811+ percentile cutoff
812+
813+ p is either an array of percentiles in [0..100] or a scalar which
814+ indicates how many quantiles of data you want ranked
815+ """
816+
817+ if not iterable (p ):
818+ p = nx .arange (100. / p , 100. , 100. / p )
819+
820+ if max (p )<= 1 or min (p )< 0 or max (p )> 100 :
821+ raise ValueError ('percentiles should be in range 0..100, not 0..1' )
822+
823+ ptiles = prctile (x , p )
824+ return nx .searchsorted (ptiles , x )
803825
804826def center_matrix (M , dim = 0 ):
805827 """
@@ -895,6 +917,9 @@ def derivs(x,t):
895917 yout = rk4(derivs, y0, t)
896918
897919
920+ If you have access to scipy, you should probably be using the
921+ scipy.integrate tools rather than this function
922+
898923 """
899924
900925 try : Ny = len (y0 )
@@ -1515,7 +1540,7 @@ def angle(x1, y1, x2, y2):
15151540 return nx .nonzero (nx .greater_equal (nx .absolute (angles ), nx .pi ))
15161541
15171542def inside_poly (points , verts ):
1518- """"
1543+ """
15191544 points is a sequence of x,y points
15201545 verts is a sequence of x,y vertices of a poygon
15211546
@@ -1527,6 +1552,7 @@ def inside_poly(points, verts):
15271552### the following code was written and submitted by Fernando Perez
15281553### from the ipython numutils package under a BSD license
15291554# begin fperez functions
1555+
15301556"""
15311557A set of convenient utilities for numerical work.
15321558
@@ -1563,6 +1589,7 @@ def inside_poly(points, verts):
15631589CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
15641590OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15651591OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1592+
15661593"""
15671594
15681595import operator
0 commit comments