Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while executing the example code of Learning Vector Quantization #37

Open
martinrioux opened this issue Nov 28, 2017 · 2 comments

Comments

@martinrioux
Copy link

martinrioux commented Nov 28, 2017

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

@zueve
Copy link
Owner

zueve commented Nov 28, 2017

really strange)

@iwmq
Copy link

iwmq commented Jun 11, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants