What's the most straightforward way to count, say, the number of 1s or 
Trues in the array? Or the number of any integer?

I was surprised to discover recently that there isn't a count() method 
as there is for Python lists. Sorry if this has been discussed already, 
but I'm wondering if there's a reason for its absence.

I came across a thread in March:

http://aspn.activestate.com/ASPN/Mail/Message/numpy-discussion/3066460

that talked a bit about this in terms of speed, but what about just the 
convenience of having a count() method?

Looks like masked arrays have a count method, don't know much about them 
though.

Also, I understand the inaccuracies when converting between binary and 
decimal floating point representations, and therefore making counting of 
a specific float value in an array somewhat undefined, yet it seems to 
work in Python lists:

 >>> 1.1
1.1000000000000001
 >>> a=[1.1, 1.1, 1.2]
 >>> a
[1.1000000000000001, 1.1000000000000001, 1.2]
 >>> a.count(1.1)
2
 >>> a.count(1.1000000000000001)
2
 >>> a.count(1.2)
1

Comments?

Martin

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion

Reply via email to