piiswrong commented on a change in pull request #10931: [MXNET-349] [WIP] Histogram Operator URL: https://github.com/apache/incubator-mxnet/pull/10931#discussion_r188034390
########## File path: python/mxnet/ndarray/ndarray.py ########## @@ -3740,3 +3740,29 @@ 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)) + + +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. + """ + + if isinstance(bins, NDArray): + return _internal._histogram(data=a, bins=bins) + elif isinstance(bins, int): + if range_ is None: + range_ = (float(a.min().asnumpy()[0]), float(a.max().asnumpy()[0])) + return _internal._histogram(data=a, bins=array([]), bin_cnt=bins, range=range_) Review comment: why make an invalid array/ ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services