piiswrong commented on a change in pull request #10931: [MXNET-349] Histogram 
Operator
URL: https://github.com/apache/incubator-mxnet/pull/10931#discussion_r192571164
 
 

 ##########
 File path: python/mxnet/ndarray/ndarray.py
 ##########
 @@ -3740,3 +3740,36 @@ def empty(shape, ctx=None, dtype=None):
     if dtype is None:
         dtype = mx_real_t
     return NDArray(handle=_new_alloc_handle(shape, ctx, False, dtype))
+
+
+# pylint: disable= redefined-builtin
+def histogram(a, bins=10, range=None):
+    """Compute the histogram of the input data.
+
+    Parameters
+    ----------
+    a : NDArray
+        Input data. The histogram is computed over the flattened array.
+    bins : int or sequence of scalars
+        If bins is an int, it defines the number of equal-width bins in the
+        given range (10, by default). If bins is a sequence, it defines the 
bin edges,
+        including the rightmost edge, allowing for non-uniform bin widths.
+    range_ : (float, float), optional
+        The lower and upper range of the bins. If not provided, range is 
simply (a.min(), a.max()).
+        Values outside the range are ignored. The first element of the range 
must be less than or
+        equal to the second. range affects the automatic bin computation as 
well, the range will
+        be equally divided by the number of bins.
+    """
+
+    # pylint: disable= no-member, protected-access
+    if isinstance(bins, NDArray):
+        return _internal._histogram(data=a, bins=bins)
+    elif isinstance(bins, integer_types):
+        if range is None:
+            warnings.warn("range_ is not specified, using numpy's result "
+                          "to ensure consistency with numpy")
+            res, bin_bounds = np.histogram(a.asnumpy(), bins=bins)
+            return array(res), array(bin_bounds)
+        return _internal._histogram(data=a, bin_cnt=bins, range=range)
+    return None
 
 Review comment:
   why return None? Shouldn't this cause an error?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to