Auerilas / ecopy

Python tools for ecological data analyses
64 stars 27 forks source link

TypeError: 'float' - Ordination tutorial #7

Closed anmwinter closed 7 years ago

anmwinter commented 7 years ago

I keep getting this message when running the MDS example in the ecopy tutorial: TypeError: 'float' object cannot be interpreted as an integer

I am running Python 3.6.x with Anaconda with ecopy installed with pip.

Full error message

TypeError Traceback (most recent call last)

in () ----> 1 dunesMDS = ep.MDS(dunes_D, transform='monotone') /Users/ara/anaconda/lib/python3.6/site-packages/ecopy/ordination/mds.py in __init__(self, distmat, siteNames, naxes, transform, ntry, tolerance, maxiter, init) 111 stressStore = 1 112 if init is None: --> 113 init2 = pcoa(distmat).U[:,:naxes] 114 else: 115 init2 = init /Users/ara/anaconda/lib/python3.6/site-packages/ecopy/ordination/pcoa.py in __init__(self, x, correction, siteNames) 96 A = -0.5*np.square(y.astype('float')) 97 n = float(y.shape[0]) ---> 98 ones = np.ones(n)[np.newaxis].T 99 I = np.eye(n) 100 D = (I - ones.dot(ones.T)/n).dot(A).dot(I - ones.dot(ones.T)/n) /Users/ara/anaconda/lib/python3.6/site-packages/numpy/core/numeric.py in ones(shape, dtype, order) 190 191 """ --> 192 a = empty(shape, dtype, order) 193 multiarray.copyto(a, 1, casting='unsafe') 194 return a TypeError: 'float' object cannot be interpreted as an integer
Auerilas commented 7 years ago

This was an error caused by

n = float(y.shape[0])

where n was a float and could not make a column of ones which required an integer. This worked in old versions of numpy, but not in the newer ones. It's been resolved. This also led me to some issues where numpy was not rounding Euclidean distances to 0 (it would give small negative numbers, like -1E-17). This has also been resolved.

I haven't been able to work on EcoPy in some time, but I'm hoping to get it on my regular schedule and have regular updates out starting this summer and next fall.