Index: /trunk/tools/generic_tools.py
===================================================================
--- /trunk/tools/generic_tools.py	(revision 1913)
+++ /trunk/tools/generic_tools.py	(revision 1914)
@@ -111,4 +111,6 @@
 # list_norepeatcombos: Function to all possible (Num-1)-combinations of a Num values without repetitions
 # lstring_values: Function to provide a new list-string from a string which is a list of word separated by a character if some values are repeated they are not included
+# maxNcounts: Function to provide a value according to the maximum number of repeated values along a given axis
+# minNcounts: Function to provide a value according to the minimum number of repeated values along a given axis
 # minmax_range: Function to provide a range for a given pair of minimum and maximum
 # multi_index_mat: Function to provide the multiple coordinates of a given value inside a matrix
@@ -13071,4 +13073,104 @@
     return newStr
 
+def maxNcounts(values, axis):
+    """ Function to provide a value according to the maximum number of repeated values along a given axis
+      values= values to count maximum values
+      axis= which axis to use to count values
+    >>> values3D = np.arange(27).reshape(3,3,3)
+    >>> values3D[2,:,:] = 3
+    >>> values3D[1,0:2,0:2] = 3
+    >>> maxNcounts(values3D, 0)
+    [[3 3 2]
+     [3 3 5]
+     [6 7 8]]
+    """
+    import module_ForSci as fsci
+
+    fname = 'maxNcounts'
+
+    shapev = list(values.shape)
+    Ndims = len(shapev)
+    if axis > len(shapev):
+        print errormsg
+        print '  ' + fname + ': axis to use:', axis, 'not in shape:', values.shapev
+        quit(-1)
+    newshape = shapev.pop(axis)
+    maxNCvalues = np.zeros(tuple(shapev), dtype=values.dtype)
+
+    origdimns = []
+    newdimns = []
+    for iid in range(Ndims):
+        origdimns.append('d'+str(iid))
+        if iid != axis: newdimns.append(origdimns[iid])
+
+    listslcs = provide_slices(origdimns, values.shape, newdimns)
+    Nslcs = len(listslcs)
+
+    for islc in range(Nslcs):
+        slicev = listslcs[islc] + []
+        slicev.pop(axis)
+        vals = values[tuple(listslcs[islc])].flatten()
+        Ndiffv, vcounts = fsci.module_scientific.ncountr(values=vals, d1=len(vals))
+        countmax = np.max(vcounts[0:Ndiffv,1])
+        idmax = index_vec(vcounts[0:Ndiffv,1],countmax)           
+
+        maxNCvalues[tuple(slicev)] = vcounts[idmax,0]
+
+    return maxNCvalues
+
+
+def minNcounts(values, axis):
+    """ Function to provide a value according to the minimum number of repeated values along a given axis
+      values= values to count maximum values
+      axis= which axis to use to count values
+    >>> values3D = np.arange(27).reshape(3,3,3)
+    >>> values3D[2,:,:] = 3
+    >>> values3D[1,0:2,0:2] = 3
+    >>> minNcounts(values3D, 0)
+    [[0 1 2]
+     [3 4 5]
+     [6 7 8]]
+    """
+    import module_ForSci as fsci
+
+    fname = 'minNcounts'
+
+    shapev = list(values.shape)
+    Ndims = len(shapev)
+    if axis > len(shapev):
+        print errormsg
+        print '  ' + fname + ': axis to use:', axis, 'not in shape:', values.shapev
+        quit(-1)
+    newshape = shapev.pop(axis)
+    minNCvalues = np.zeros(tuple(shapev), dtype=values.dtype)
+
+    origdimns = []
+    newdimns = []
+    for iid in range(Ndims):
+        origdimns.append('d'+str(iid))
+        if iid != axis: newdimns.append(origdimns[iid])
+
+    listslcs = provide_slices(origdimns, values.shape, newdimns)
+    Nslcs = len(listslcs)
+
+    for islc in range(Nslcs):
+        slicev = listslcs[islc] + []
+        slicev.pop(axis)
+        vals = values[tuple(listslcs[islc])].flatten()
+        Ndiffv, vcounts = fsci.module_scientific.ncountr(values=vals, d1=len(vals))
+        countmax = np.min(vcounts[0:Ndiffv,1])
+        idmax = index_vec(vcounts[0:Ndiffv,1],countmax)           
+
+        minNCvalues[tuple(slicev)] = vcounts[idmax,0]
+
+    return minNCvalues
+
+values3D = np.arange(27).reshape(3,3,3)
+values3D[2,:,:] = 3
+values3D[1,0:2,0:2] = 3
+print values3D
+print maxNcounts(values3D, 0)
+print minNcounts(values3D, 0)
+
 #quit()
 
