Error while executing the example code of Learning Vector Quantization
martinrioux opened this issue · 2 comments
From this page: https://pythonhosted.org/neurolab/ex_newlvq.html
Using numpy 1.13.3 and neurolab 0.3.5
The error message I got was:
Traceback (most recent call last):
File "learning_vector.py", line 20, in <module>
net = nl.net.newlvq(nl.tool.minmax(input), 4, [.6, .4])
File "/usr/local/lib/python2.7/dist-packages/neurolab/net.py", line 179, in newlvq
layer_out.np['w'][n][st:i].fill(1.0)
TypeError: slice indices must be integers or None or have an __index__ method
I fixed the issue by editing the neurolab/net.py and changing the line 127 from
layer_out.np['w'][n][st:i].fill(1.0)
to
layer_out.np['w'][n][int(st):int(i)].fill(1.0)
Thanks!
Martin Rioux
really strange)
Hey guys, this is caused by line 176 in the file neurolab/net.py (version 0.3.5):
inx = np.floor(cn0 * pc.cumsum())
The resulting inx contains an array of floating numbers, while array slicing requires integers as indices.
The fix is to cast the array of type float to an array of type integer.
inx = np.floor(cn0 * pc.cumsum()).astype(int)
Hope my advice help.
@zueve @martinrioux