count hits with numpy

23Jul10

I have an array where I record hits
a=np.zeros(5)
and an array with the indices of the hits, for example I have 2 hits on index 2
hits=np.array([2,2])
so I want to increase index 2 of a by 2

I tried:
a[hits]+=1
but it gives array([ 0., 0., 1., 0., 0.])
does someone have a suggestion?
bins=np.bincount(hits)
a[:len(bins)] += bins
a
array([ 0., 0., 2., 0., 0.])



No Responses Yet to “count hits with numpy”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.