ncullen93 / pyBN

Bayesian Networks in Python
MIT License
146 stars 55 forks source link

Newer versions of numpy (>= 1.12.0) does not accept float as array index #22

Open Mestrace opened 6 years ago

Mestrace commented 6 years ago

Encountered this problem on pyBN/pyBN/classes/factor.py, method reduce_factor ` 585 """ 586 exp_len = len(self.cpt)/float(self.card[rv]) --> 587 new_cpt = np.zeros((exp_len,)) 588 589 val_idx = self.bn.F[rv]['values'].index(val)

TypeError: 'float' object cannot be interpreted as an index`

In line 587, the exp_len will be type float and the newer version of numpy does not accept it.

From numpy release note:

DeprecationWarning to error

Indexing with floats raises IndexError, e.g., a[0, 0.0]. Indexing with non-integer array_like raises IndexError, e.g., a['1', '2'] Indexing with multiple ellipsis raises IndexError, e.g., a[..., ...]. Non-integers used as index values raise TypeError, e.g., in reshape, take, and specifying reduce axis.

I reinstall the numpy==1.11.3 and that fixed the problem. But I suggest that the type should be cast to int, and there might be other places that has the same problem, too.