[Numpy-discussion] np.bincount() won't accept list or array from np.random.beta and acts like len

Michael mnandris@blueyonder.co...
Sat Aug 9 15:19:47 CDT 2008

Hi list,

I have found np.bincount() not to behave as expected when provided with
data from np.random.beta.

It works fine with lists, but not the type returned by np.random.beta...
there seems to be a block on casting too. When it does give output on
np.array it just reports the number of items, like len()


x = np.array([1,1,1,1,2,2,4,4,5,6,6,6])
print np.bincount(x)

prior = np.random.beta(2,7,1000)
a = prior.tolist()

print type(a)    
print np.bincount(a)

b = [ round(i,2) for i in a ] 
print b; print type(b)
print np.bincount(b) 
#c = np.array(a)
#print np.bincount(c); print type(c)

i know its easily solved but bincount is probably faster than making a
pass over the probabilities and hashing them as strings etc

have got a class that subclasses dict and accepts np.random.beta as
	for prob in seq: 
	    self.bincount( prob )

    def bincount( self, pr, increment=1 ):
	strPr = str(round(pr,self.dp)) 			
 	self[strPr] = increment + self.get( strPr, 0 )

would prefer the one-liner:

    self.bincount = np.bincount(seq) 	

any ideas? 


Michael Nandris

(btw apologies for the cross posting)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080809/a5a91cba/attachment.bin 

More information about the Numpy-discussion mailing list