Repository navigation
Commit 0991272
committed
ENH: add an axis argument to np.bincount
This adds an axis argument to np.bincount, which can now take multidimensional
arrays and do the counting over an arbitrary number of axes. `axis` defaults
to `None`, which does the counting over all the axes, i.e. over the flattened
array.
The shape of the output is computed by removing from `list` (the input array)
all dimensions in `axis`, and appending a dimension of length
`max(max(list) + 1, minlength)` to the end. `out[..., n]` will hold the number
of occurrences of `n` at the given position over the selected axes.
If a `weights` argument is provided, its shape is broadcasted with `list`
before removing the axes. In this case, `axis` refers to the axes of `list`
*before* broadcasting, and `out[..., n]` will hold the sum of `weights` over
the selected axes, at all positions where `list` takes the value `n`.
The general case is handled with nested iterators, but shortcuts without
having to set up an iterator are provided for 1D cases, with no performance
loss against the previous version.
As a plus, this PR also solves numpy#823, by providing specialized functions for
all integer types to find the max. There are also specialized functions for
all integer types for counting and doing weighted counting.1 parent db198d5 commit 0991272
5 files changed
Lines changed: 868 additions & 125 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4987 | 4987 | | |
4988 | 4988 | | |
4989 | 4989 | | |
4990 | | - | |
| 4990 | + | |
4991 | 4991 | | |
4992 | | - | |
| 4992 | + | |
| 4993 | + | |
4993 | 4994 | | |
4994 | | - | |
4995 | | - | |
4996 | | - | |
4997 | | - | |
4998 | | - | |
4999 | | - | |
5000 | | - | |
5001 | | - | |
| 4995 | + | |
| 4996 | + | |
| 4997 | + | |
| 4998 | + | |
5002 | 4999 | | |
5003 | 5000 | | |
5004 | 5001 | | |
5005 | | - | |
| 5002 | + | |
5006 | 5003 | | |
5007 | 5004 | | |
5008 | | - | |
| 5005 | + | |
5009 | 5006 | | |
5010 | 5007 | | |
5011 | | - | |
5012 | 5008 | | |
| 5009 | + | |
| 5010 | + | |
| 5011 | + | |
| 5012 | + | |
5013 | 5013 | | |
5014 | 5014 | | |
5015 | 5015 | | |
5016 | | - | |
| 5016 | + | |
5017 | 5017 | | |
5018 | | - | |
5019 | 5018 | | |
5020 | 5019 | | |
5021 | 5020 | | |
5022 | 5021 | | |
5023 | | - | |
5024 | | - | |
| 5022 | + | |
| 5023 | + | |
| 5024 | + | |
5025 | 5025 | | |
5026 | | - | |
| 5026 | + | |
| 5027 | + | |
5027 | 5028 | | |
5028 | 5029 | | |
5029 | 5030 | | |
5030 | 5031 | | |
5031 | 5032 | | |
| 5033 | + | |
| 5034 | + | |
| 5035 | + | |
| 5036 | + | |
| 5037 | + | |
| 5038 | + | |
| 5039 | + | |
| 5040 | + | |
| 5041 | + | |
5032 | 5042 | | |
5033 | 5043 | | |
5034 | 5044 | | |
| |||
5037 | 5047 | | |
5038 | 5048 | | |
5039 | 5049 | | |
5040 | | - | |
| 5050 | + | |
5041 | 5051 | | |
5042 | 5052 | | |
5043 | 5053 | | |
| |||
5046 | 5056 | | |
5047 | 5057 | | |
5048 | 5058 | | |
5049 | | - | |
| 5059 | + | |
5050 | 5060 | | |
5051 | | - | |
5052 | | - | |
| 5061 | + | |
| 5062 | + | |
5053 | 5063 | | |
5054 | 5064 | | |
5055 | 5065 | | |
5056 | 5066 | | |
5057 | 5067 | | |
5058 | 5068 | | |
| 5069 | + | |
| 5070 | + | |
| 5071 | + | |
| 5072 | + | |
| 5073 | + | |
| 5074 | + | |
| 5075 | + | |
| 5076 | + | |
| 5077 | + | |
| 5078 | + | |
| 5079 | + | |
| 5080 | + | |
| 5081 | + | |
| 5082 | + | |
| 5083 | + | |
| 5084 | + | |
| 5085 | + | |
| 5086 | + | |
| 5087 | + | |
| 5088 | + | |
| 5089 | + | |
| 5090 | + | |
| 5091 | + | |
| 5092 | + | |
| 5093 | + | |
| 5094 | + | |
5059 | 5095 | | |
5060 | 5096 | | |
5061 | 5097 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
0 commit comments