@Vinzenz, it looks like the double forward slash used in your Python code is causing the code translation issue, probably because // is used for commenting in JS. However, you are also going to have issues using numpy libraries in JS. You will need to find alternative methods that do not rely on Python libraries.
Thank you for your reply. I try to cenvert it, but am right now wondering, if there is an overview about workarounds for numpy components (in my case: np.ones , np.random.permutation, np.append) or if it would be possible to do the same thing I wish to accomplish with the stimNoise component? Can I change this from a 50/50 background/noise distribution?
@Vinzenz, could you share the error? It may be from n_l.slice(0, Number.parseInt(n_black_l)) = 1;, as you cannot assign a variable to a slice like that. It looks like you are trying to convert a range of values in that array to 1, and to do that you could use the map method, using something along the lines of
You can narrow this down by opening the JS console in your browser when the error occurs (in Chrome, it’s under view -> developer). That will give you an actual line number and tell you which statement it’s having trouble with.
But now I receive the following error message: TypeError: Math.ones is not a function
I exchanged the component np.ones with Math.ones and based on my research I assumed it does the same. Was I wrong?
JavaScript’s built in Math library doesn’t seem to have a ones() function. I suspect you’ve come across that function in the 3rd party math.js package:
I don’t know enough about JavaScript to advise whether or how you could install that library and access its functions from your script, but this thread might be useful:
Thank you htat soves the problem with math.ones. It is just really troublesome that the link to the library gets lost every time I synchronize my experiment.
But now I receive the error: TypeError: n_l.map is not a function . I assumed it would be because math.ones gives no array back, but this should be the case.
Not sure what math.ones is, but it is not part of the Math package. Try using the following instead to populate n_l and n_r with -1 values instead of math.ones
n_l = [...Array(size/2).keys()].fill(-1)
Now you should have an array that has the map method. In the previous answer, val and index are arguments that are passed to the map function, I used names that aimed to explain how those values are used in the method, so val is the actual val for that particular index - see Mozilla map docs . Its similar to the following in Python:
I was looking into this, in math.js ones(n) just creates an array of length n filled with the number 1. It indeed does not exist in JS’s native Math library, which is the source of that error. So, the “fill” solution should just solve that problem.