I am new to numpy(and python) and working on making the edit distance Algorithm with numpy. This is my code so far. I have an error for the first line after the else: . The error says: “index 3 is out of bounds for axis 0 with size 2”. I’m very confused as to what this means. I also have a question about how I’m initializing my T array – am I doing it in the best way? It took me a while to figure out how to make an empty 2d array that are 1 column and 1 row wide. Any guidance would be super helpful!
i = len(string1) - 1 j = len(string2) - 1 T = np.array([[1,1],[1,1]]) if string1[i] == string2[j]: T[i][j] = T[i-1][j-1] else: T[i][j] = 1 + min(T[i-1][j], T[i-1][j-1], T[i][j-1]) assert(edit_distance('hello', 'relevant') == 6) assert(edit_distance('elephant', 'relevant') == 3) assert(edit_distance('statistics', 'mathematics') == 6) assert(edit_distance('numpy', 'alexa') == 5)```
This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.