r""" Compute the histogram of a dataset. Parameters ---------- a : array_like Input data. The histogram is computed over the flattened array. bins : int or sequence of scalars or str, optional If `bins` is an int, it defines the number of equal-width bins
(a, bins=10, range=None, density=None, weights=None)
| 684 | |
| 685 | @array_function_dispatch(_histogram_dispatcher) |
| 686 | def histogram(a, bins=10, range=None, density=None, weights=None): |
| 687 | r""" |
| 688 | Compute the histogram of a dataset. |
| 689 | |
| 690 | Parameters |
| 691 | ---------- |
| 692 | a : array_like |
| 693 | Input data. The histogram is computed over the flattened array. |
| 694 | bins : int or sequence of scalars or str, optional |
| 695 | If `bins` is an int, it defines the number of equal-width |
| 696 | bins in the given range (10, by default). If `bins` is a |
| 697 | sequence, it defines a monotonically increasing array of bin edges, |
| 698 | including the rightmost edge, allowing for non-uniform bin widths. |
| 699 | |
| 700 | If `bins` is a string, it defines the method used to calculate the |
| 701 | optimal bin width, as defined by `histogram_bin_edges`. |
| 702 | |
| 703 | range : (float, float), optional |
| 704 | The lower and upper range of the bins. If not provided, range |
| 705 | is simply ``(a.min(), a.max())``. Values outside the range are |
| 706 | ignored. The first element of the range must be less than or |
| 707 | equal to the second. `range` affects the automatic bin |
| 708 | computation as well. While bin width is computed to be optimal |
| 709 | based on the actual data within `range`, the bin count will fill |
| 710 | the entire range including portions containing no data. |
| 711 | weights : array_like, optional |
| 712 | An array of weights, of the same shape as `a`. Each value in |
| 713 | `a` only contributes its associated weight towards the bin count |
| 714 | (instead of 1). If `density` is True, the weights are |
| 715 | normalized, so that the integral of the density over the range |
| 716 | remains 1. |
| 717 | Please note that the ``dtype`` of `weights` will also become the |
| 718 | ``dtype`` of the returned accumulator (`hist`), so it must be |
| 719 | large enough to hold accumulated values as well. |
| 720 | density : bool, optional |
| 721 | If ``False``, the result will contain the number of samples in |
| 722 | each bin. If ``True``, the result is the value of the |
| 723 | probability *density* function at the bin, normalized such that |
| 724 | the *integral* over the range is 1. Note that the sum of the |
| 725 | histogram values will not be equal to 1 unless bins of unity |
| 726 | width are chosen; it is not a probability *mass* function. |
| 727 | |
| 728 | Returns |
| 729 | ------- |
| 730 | hist : array |
| 731 | The values of the histogram. See `density` and `weights` for a |
| 732 | description of the possible semantics. If `weights` are given, |
| 733 | ``hist.dtype`` will be taken from `weights`. |
| 734 | bin_edges : array of dtype float |
| 735 | Return the bin edges ``(length(hist)+1)``. |
| 736 | |
| 737 | |
| 738 | See Also |
| 739 | -------- |
| 740 | histogramdd, bincount, searchsorted, digitize, histogram_bin_edges |
| 741 | |
| 742 | Notes |
| 743 | ----- |
searching dependent graphs…