Rkz
Rkz

Reputation: 1257

numpy multinomial function returns value error

I am using the numpy.random.multinomial(1,val) NumpyMultinomial, where val is a 1-D numpy array. The function gives the following error:

ValueError('sum(pvals[:-1]) > 1.0',)

However, I checked the sum of the input array val using val.sum() and it sums exactly to 1. I don't know if the multinomial function has some bug. Can some one help me out with this. Alternatively, is there any other python module that I can use for sampling using multinomial distribution?

Upvotes: 1

Views: 1377

Answers (1)

Rkz
Rkz

Reputation: 1257

I found that this strange behaviour is due to negative values in the array val. Actually I had a case where the val summed to 0.9999996, but it contained a negative element and due to this Multinomial function throws up the ValueError, which completely misleading of course because the sum never exceeded 1.

Upvotes: 1

Related Questions