[Numpy-discussion] New functions.

Mark Miller markperrymiller@gmail....
Wed Jun 1 11:49:16 CDT 2011


Not quite. Bincount is fine if you have a set of approximately
sequential numbers. But if you don't....

>>> a = numpy.array((1,500,1000))
>>> a
array([   1,  500, 1000])
>>> b = numpy.bincount(a)
>>> b
array([0, 1, 0, ..., 0, 0, 1])
>>> len(b)
1001

-Mark


On Wed, Jun 1, 2011 at 9:32 AM, Skipper Seabold <jsseabold@gmail.com> wrote:
> On Wed, Jun 1, 2011 at 11:31 AM, Mark Miller <markperrymiller@gmail.com> wrote:
>> I'd love to see something like a "count_unique" function included. The
>> numpy.unique function is handy, but it can be a little awkward to
>> efficiently go back and get counts of each unique value after the
>> fact.
>>
>
> Does bincount do what you're after?
>
> [~/]
> [1]: x = np.random.randint(1,6,5)
>
> [~/]
> [2]: x
> [2]: array([1, 3, 4, 5, 1])
>
> [~/]
> [3]: np.bincount(x)
> [3]: array([0, 2, 0, 1, 1, 1])
>
> Skipper
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list