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