frequency count or number of occurences of a number in an array

Larry larry.cebuala at gmail.com
Wed Mar 12 06:26:58 EDT 2008


Dear all,

I'm new to Python. I have a file (an image file actually) that I need
to read pixel by pixel. It's an 8-bit integer type. I need to get the
statistics like mean, standard deviation, etc., which I know a little
bit already from reading numpy module. What I want to know is how to
get the number of occurences of numeric element in an array. Say,

b = array(([2, 2, 3, 4, 5, 5])

b.count(2) certainly does not work. Is there any more efficient way
other than converting this as string characters? My data will produce
a fairly large array like 400x400 = 160000 values. Hoping you guys can
help me.

Larry



More information about the Python-list mailing list