Write me a numba implementation of levensthin distance, taking two numpy int arrays. Call it levenshtein. Run it in nopython mode. Character swaps are cost 2.
Write me a numba implementation of levensthin distance, taking two numpy int arrays. Call it levenshtein. Run it in nopython mode. Character swaps are cost 2.
To implement the Levenshtein distance with character swaps costing 2 using Numba in nopython mode, you can follow the code snippet below. This implementation takes two NumPy integer arrays as input and computes the Levenshtein distance between them. First, make sure you have Numba and NumPy installed in your environment. If not, you can install them using pip:
1 | pip install numba numpy |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import numpy as np from numba import njit @njit def levenshtein(a: np.ndarray, b: np.ndarray) -> int: len_a = len(a) len_b = len(b) # Create a distance matrix dp = np.zeros((len_a + 1, len_b + 1), dtype=np.int32) # Initialize the distance matrix for i in range(len_a + 1): dp[i][0] = i # Deletion cost for j in range(len_b + 1): dp[0][j] = j # Insertion cost # Fill the distance matrix for i in range(1, len_a + 1): for j in range(1, len_b + 1): cost = 0 if a[i - 1] == b[j - 1] else 1 dp[i][j] = min( dp[i - 1][j] + 1, # Deletion dp[i][j - 1] + 1, # Insertion dp[i - 1][j - 1] + cost # Substitution ) if i > 1 and j > 1 and a[i - 1] == b[j - 2] and a[i - 2] == b[j - 1]: # Character swap cost dp[i][j] = min(dp[i][j], dp[i - 2][j - 2] + 2) return dp[len_a][len_b] # Example Usage a = np.array([1, 2, 3, 4]) b = np.array([1, 4, 3, 2]) distance = levenshtein(a, b) print("Levenshtein distance:", distance) |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import numpy as np from numba import njit @njit def levenshtein(a: np.ndarray, b: np.ndarray) -> int: len_a = len(a) len_b = len(b) # Create a distance matrix dp = np.zeros((len_a + 1, len_b + 1), dtype=np.int32) # Initialize the distance matrix for i in range(len_a + 1): dp[i][0] = i # Deletion cost for j in range(len_b + 1): dp[0][j] = j # Insertion cost # Fill the distance matrix for i in range(1, len_a + 1): for j in range(1, len_b + 1): cost = 0 if a[i - 1] == b[j - 1] else 1 dp[i][j] = min( dp[i - 1][j] + 1, # Deletion dp[i][j - 1] + 1, # Insertion dp[i - 1][j - 1] + cost # Substitution ) if i > 1 and j > 1 and a[i - 1] == b[j - 2] and a[i - 2] == b[j - 1]: # Character swap cost dp[i][j] = min(dp[i][j], dp[i - 2][j - 2] + 2) return dp[len_a][len_b] |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | import numpy as np from numba import njit @njit def levenshtein(a: np.ndarray, b: np.ndarray) -> int: len_a = len(a) len_b = len(b) # Create a distance matrix dp = np.zeros((len_a + 1, len_b + 1), dtype=np.int32) # Initialize the distance matrix for i in range(len_a + 1): dp[i][0] = i # Deletion cost for j in range(len_b + 1): dp[0][j] = j # Insertion cost # Fill the distance matrix for i in range(1, len_a + 1): for j in range(1, len_b + 1): cost = 0 if a[i - 1] == b[j - 1] else 1 dp[i][j] = min( dp[i - 1][j] + 1, # Deletion dp[i][j - 1] + 1, # Insertion dp[i - 1][j - 1] + cost # Substitution ) if i > 1 and j > 1 and a[i - 1] == b[j - 2] and a[i - 2] == b[j - 1]: # Character swap cost dp[i][j] = min(dp[i][j], dp[i - 2][j - 2] + 2) return dp[len_a][len_b] answer = levenshtein(np.array([3, 5, 2, 4, 8, 7]), np.array([3, 4, 2, 4, 8, 7, 9])) expected = 3 assert answer == expected, f'Wrong answer; got {answer} instead of {expected}' print('All tests passed') |
Traceback (most recent call last):
File "/usr/src/app/main.py", line 40, in <module>
assert answer == expected, f'Wrong answer; got {answer} instead of {expected}'
AssertionError: Wrong answer; got 2 instead of 3
Testing if the previous output contains the string All tests passed
: False
Testing if the previous output contains the string njit
: True
Testing if the previous output contains the string nopython
: False
Testing if the previous output contains the string import numba
: False
Testing if the previous output contains the string from numba
: True
Write me a numba implementation of levensthin distance, taking two numpy int arrays. Call it levenshtein. Run it in nopython mode. Character swaps are cost 2.
Write me a numba implementation of levensthin distance, taking two numpy int arrays. Call it levenshtein. Run it in nopython mode. Character swaps are cost 2.
Certainly! Below is a Numba implementation of the Levenshtein distance that takes two NumPy integer arrays as input and runs in nopython mode. The cost for character substitutions (swaps) is set to 2, while deletions and insertions have a cost of 1. Please make sure you have Numba and NumPy installed in your Python environment. You can install them using pip if you haven't already:
1 | pip install numba numpy |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import numpy as np from numba import njit @njit def levenshtein(arr1, arr2): len1 = len(arr1) len2 = len(arr2) # Create a distance matrix dp = np.zeros((len1 + 1, len2 + 1), dtype=np.int64) # Initialize the distance matrix for i in range(len1 + 1): dp[i][0] = i # Cost of deletions for j in range(len2 + 1): dp[0][j] = j # Cost of insertions # Fill the distance matrix for i in range(1, len1 + 1): for j in range(1, len2 + 1): cost = 0 if arr1[i - 1] == arr2[j - 1] else 2 # Cost of substitution dp[i][j] = min( dp[i - 1][j] + 1, # Deletion dp[i][j - 1] + 1, # Insertion dp[i - 1][j - 1] + cost # Substitution ) return dp[len1][len2] # Example usage if __name__ == "__main__": arr1 = np.array([1, 2, 3, 4], dtype=np.int64) arr2 = np.array([1, 2, 4, 3], dtype=np.int64) distance = levenshtein(arr1, arr2) print("Levenshtein distance:", distance) |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import numpy as np from numba import njit @njit def levenshtein(arr1, arr2): len1 = len(arr1) len2 = len(arr2) # Create a distance matrix dp = np.zeros((len1 + 1, len2 + 1), dtype=np.int64) # Initialize the distance matrix for i in range(len1 + 1): dp[i][0] = i # Cost of deletions for j in range(len2 + 1): dp[0][j] = j # Cost of insertions # Fill the distance matrix for i in range(1, len1 + 1): for j in range(1, len2 + 1): cost = 0 if arr1[i - 1] == arr2[j - 1] else 2 # Cost of substitution dp[i][j] = min( dp[i - 1][j] + 1, # Deletion dp[i][j - 1] + 1, # Insertion dp[i - 1][j - 1] + cost # Substitution ) return dp[len1][len2] |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import numpy as np from numba import njit @njit def levenshtein(arr1, arr2): len1 = len(arr1) len2 = len(arr2) # Create a distance matrix dp = np.zeros((len1 + 1, len2 + 1), dtype=np.int64) # Initialize the distance matrix for i in range(len1 + 1): dp[i][0] = i # Cost of deletions for j in range(len2 + 1): dp[0][j] = j # Cost of insertions # Fill the distance matrix for i in range(1, len1 + 1): for j in range(1, len2 + 1): cost = 0 if arr1[i - 1] == arr2[j - 1] else 2 # Cost of substitution dp[i][j] = min( dp[i - 1][j] + 1, # Deletion dp[i][j - 1] + 1, # Insertion dp[i - 1][j - 1] + cost # Substitution ) return dp[len1][len2] answer = levenshtein(np.array([3, 5, 2, 4, 8, 7]), np.array([3, 4, 2, 4, 8, 7, 9])) expected = 3 assert answer == expected, f'Wrong answer; got {answer} instead of {expected}' print('All tests passed') |
All tests passed
Testing if the previous output contains the string All tests passed
: True
Testing if the previous output contains the string njit
: True
Testing if the previous output contains the string nopython
: False
Testing if the previous output contains the string import numba
: False
Testing if the previous output contains the string from numba
: True
Write me a numba implementation of levensthin distance, taking two numpy int arrays. Call it levenshtein. Run it in nopython mode. Character swaps are cost 2.
Write me a numba implementation of levensthin distance, taking two numpy int arrays. Call it levenshtein. Run it in nopython mode. Character swaps are cost 2.
Certainly! Below is a Numba implementation of the Levenshtein distance algorithm that accounts for character swaps with a cost of 2. This implementation will utilize Numba's `@njit` decorator to run in nopython mode. The function takes two NumPy integer arrays as input. First, ensure you have Numba and NumPy installed in your environment. You can install them using pip if you haven't already:
1 | pip install numba numpy |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import numpy as np from numba import njit @njit def levenshtein(a, b): len_a = len(a) len_b = len(b) # Create a distance matrix dp = np.zeros((len_a + 1, len_b + 1), dtype=np.int32) # Initialize the distance matrix for i in range(len_a + 1): dp[i][0] = i # Deletion cost for j in range(len_b + 1): dp[0][j] = j # Insertion cost # Compute the Levenshtein distance for i in range(1, len_a + 1): for j in range(1, len_b + 1): cost = 0 if a[i - 1] == b[j - 1] else 1 # Calculate minimum cost dp[i][j] = min(dp[i - 1][j] + 1, # Deletion dp[i][j - 1] + 1, # Insertion dp[i - 1][j - 1] + cost) # Substitution # Check for character swap if i > 1 and j > 1 and a[i - 1] == b[j - 2] and a[i - 2] == b[j - 1]: dp[i][j] = min(dp[i][j], dp[i - 2][j - 2] + 2) # Swap cost return dp[len_a][len_b] # Example usage if __name__ == "__main__": a = np.array([1, 2, 3, 4]) b = np.array([1, 3, 2, 4]) distance = levenshtein(a, b) print("Levenshtein distance:", distance) |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import numpy as np from numba import njit @njit def levenshtein(a, b): len_a = len(a) len_b = len(b) # Create a distance matrix dp = np.zeros((len_a + 1, len_b + 1), dtype=np.int32) # Initialize the distance matrix for i in range(len_a + 1): dp[i][0] = i # Deletion cost for j in range(len_b + 1): dp[0][j] = j # Insertion cost # Compute the Levenshtein distance for i in range(1, len_a + 1): for j in range(1, len_b + 1): cost = 0 if a[i - 1] == b[j - 1] else 1 # Calculate minimum cost dp[i][j] = min(dp[i - 1][j] + 1, # Deletion dp[i][j - 1] + 1, # Insertion dp[i - 1][j - 1] + cost) # Substitution # Check for character swap if i > 1 and j > 1 and a[i - 1] == b[j - 2] and a[i - 2] == b[j - 1]: dp[i][j] = min(dp[i][j], dp[i - 2][j - 2] + 2) # Swap cost return dp[len_a][len_b] |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import numpy as np from numba import njit @njit def levenshtein(a, b): len_a = len(a) len_b = len(b) # Create a distance matrix dp = np.zeros((len_a + 1, len_b + 1), dtype=np.int32) # Initialize the distance matrix for i in range(len_a + 1): dp[i][0] = i # Deletion cost for j in range(len_b + 1): dp[0][j] = j # Insertion cost # Compute the Levenshtein distance for i in range(1, len_a + 1): for j in range(1, len_b + 1): cost = 0 if a[i - 1] == b[j - 1] else 1 # Calculate minimum cost dp[i][j] = min(dp[i - 1][j] + 1, # Deletion dp[i][j - 1] + 1, # Insertion dp[i - 1][j - 1] + cost) # Substitution # Check for character swap if i > 1 and j > 1 and a[i - 1] == b[j - 2] and a[i - 2] == b[j - 1]: dp[i][j] = min(dp[i][j], dp[i - 2][j - 2] + 2) # Swap cost return dp[len_a][len_b] answer = levenshtein(np.array([3, 5, 2, 4, 8, 7]), np.array([3, 4, 2, 4, 8, 7, 9])) expected = 3 assert answer == expected, f'Wrong answer; got {answer} instead of {expected}' print('All tests passed') |
Traceback (most recent call last):
File "/usr/src/app/main.py", line 41, in <module>
assert answer == expected, f'Wrong answer; got {answer} instead of {expected}'
AssertionError: Wrong answer; got 2 instead of 3
Testing if the previous output contains the string All tests passed
: False
Testing if the previous output contains the string njit
: True
Testing if the previous output contains the string nopython
: False
Testing if the previous output contains the string import numba
: False
Testing if the previous output contains the string from numba
: True
Write me a numba implementation of levensthin distance, taking two numpy int arrays. Call it levenshtein. Run it in nopython mode. Character swaps are cost 2.
Write me a numba implementation of levensthin distance, taking two numpy int arrays. Call it levenshtein. Run it in nopython mode. Character swaps are cost 2.
You can use Numba to implement the Levenshtein distance with the specified requirements. The following code provides a Numba implementation of the Levenshtein distance algorithm, taking two numpy integer arrays as input. It operates in nopython mode and considers character swaps to have a cost of 2. Here's the implementation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import numpy as np from numba import njit @njit def levenshtein(s1: np.ndarray, s2: np.ndarray) -> int: len_s1 = s1.shape[0] len_s2 = s2.shape[0] # Create a distance matrix dp = np.zeros((len_s1 + 1, len_s2 + 1), dtype=np.int32) # Initialize the distance matrix for i in range(len_s1 + 1): dp[i][0] = i for j in range(len_s2 + 1): dp[0][j] = j # Compute the Levenshtein distance for i in range(1, len_s1 + 1): for j in range(1, len_s2 + 1): cost = 0 if s1[i - 1] == s2[j - 1] else 1 dp[i][j] = min( dp[i - 1][j] + 1, # Deletion dp[i][j - 1] + 1, # Insertion dp[i - 1][j - 1] + cost # Substitution ) # Check for character swap if i > 1 and j > 1 and s1[i - 1] == s2[j - 2] and s1[i - 2] == s2[j - 1]: dp[i][j] = min(dp[i][j], dp[i - 2][j - 2] + 2) # Swap cost return dp[len_s1][len_s2] # Example usage s1 = np.array([1, 2, 3, 4]) # Example input as integer arrays s2 = np.array([1, 3, 2, 4]) distance = levenshtein(s1, s2) print("Levenshtein distance:", distance) |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import numpy as np from numba import njit @njit def levenshtein(s1: np.ndarray, s2: np.ndarray) -> int: len_s1 = s1.shape[0] len_s2 = s2.shape[0] # Create a distance matrix dp = np.zeros((len_s1 + 1, len_s2 + 1), dtype=np.int32) # Initialize the distance matrix for i in range(len_s1 + 1): dp[i][0] = i for j in range(len_s2 + 1): dp[0][j] = j # Compute the Levenshtein distance for i in range(1, len_s1 + 1): for j in range(1, len_s2 + 1): cost = 0 if s1[i - 1] == s2[j - 1] else 1 dp[i][j] = min( dp[i - 1][j] + 1, # Deletion dp[i][j - 1] + 1, # Insertion dp[i - 1][j - 1] + cost # Substitution ) # Check for character swap if i > 1 and j > 1 and s1[i - 1] == s2[j - 2] and s1[i - 2] == s2[j - 1]: dp[i][j] = min(dp[i][j], dp[i - 2][j - 2] + 2) # Swap cost return dp[len_s1][len_s2] # Example usage s1 = np.array([1, 2, 3, 4]) # Example input as integer arrays s2 = np.array([1, 3, 2, 4]) distance = levenshtein(s1, s2) print("Levenshtein distance:", distance) |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import numpy as np from numba import njit @njit def levenshtein(s1: np.ndarray, s2: np.ndarray) -> int: len_s1 = s1.shape[0] len_s2 = s2.shape[0] # Create a distance matrix dp = np.zeros((len_s1 + 1, len_s2 + 1), dtype=np.int32) # Initialize the distance matrix for i in range(len_s1 + 1): dp[i][0] = i for j in range(len_s2 + 1): dp[0][j] = j # Compute the Levenshtein distance for i in range(1, len_s1 + 1): for j in range(1, len_s2 + 1): cost = 0 if s1[i - 1] == s2[j - 1] else 1 dp[i][j] = min( dp[i - 1][j] + 1, # Deletion dp[i][j - 1] + 1, # Insertion dp[i - 1][j - 1] + cost # Substitution ) # Check for character swap if i > 1 and j > 1 and s1[i - 1] == s2[j - 2] and s1[i - 2] == s2[j - 1]: dp[i][j] = min(dp[i][j], dp[i - 2][j - 2] + 2) # Swap cost return dp[len_s1][len_s2] # Example usage s1 = np.array([1, 2, 3, 4]) # Example input as integer arrays s2 = np.array([1, 3, 2, 4]) distance = levenshtein(s1, s2) print("Levenshtein distance:", distance) answer = levenshtein(np.array([3, 5, 2, 4, 8, 7]), np.array([3, 4, 2, 4, 8, 7, 9])) expected = 3 assert answer == expected, f'Wrong answer; got {answer} instead of {expected}' print('All tests passed') |
Levenshtein distance: 2
Traceback (most recent call last):
File "/usr/src/app/main.py", line 48, in <module>
assert answer == expected, f'Wrong answer; got {answer} instead of {expected}'
AssertionError: Wrong answer; got 2 instead of 3
Testing if the previous output contains the string All tests passed
: False
Testing if the previous output contains the string njit
: True
Testing if the previous output contains the string nopython
: False
Testing if the previous output contains the string import numba
: False
Testing if the previous output contains the string from numba
: True
Write me a numba implementation of levensthin distance, taking two numpy int arrays. Call it levenshtein. Run it in nopython mode. Character swaps are cost 2.
Write me a numba implementation of levensthin distance, taking two numpy int arrays. Call it levenshtein. Run it in nopython mode. Character swaps are cost 2.
Certainly! Below is a Numba implementation of the Levenshtein distance algorithm that takes two NumPy integer arrays as input and runs in nopython mode. In this implementation, character swaps have a cost of 2, while insertions and deletions have a cost of 1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | import numpy as np from numba import njit @njit def levenshtein(a: np.ndarray, b: np.ndarray) -> int: # Lengths of the input arrays len_a = a.shape[0] len_b = b.shape[0] # Create a distance matrix dp = np.zeros((len_a + 1, len_b + 1), dtype=np.int32) # Initialize the distance matrix for i in range(len_a + 1): dp[i, 0] = i # Deletion cost for j in range(len_b + 1): dp[0, j] = j # Insertion cost # Compute the Levenshtein distance for i in range(1, len_a + 1): for j in range(1, len_b + 1): cost = 0 if a[i - 1] == b[j - 1] else 1 dp[i, j] = min( dp[i - 1, j] + 1, # Deletion dp[i, j - 1] + 1, # Insertion dp[i - 1, j - 1] + cost # Substitution ) # Check for swap (only if i and j are greater than 1) if i > 1 and j > 1 and a[i - 1] == b[j - 2] and a[i - 2] == b[j - 1]: dp[i, j] = min(dp[i, j], dp[i - 2, j - 2] + 2) # Swap cost return dp[len_a, len_b] # Example usage if __name__ == "__main__": arr1 = np.array([1, 2, 3, 4]) arr2 = np.array([1, 3, 2, 4]) distance = levenshtein(arr1, arr2) print("Levenshtein distance:", distance) |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | import numpy as np from numba import njit @njit def levenshtein(a: np.ndarray, b: np.ndarray) -> int: # Lengths of the input arrays len_a = a.shape[0] len_b = b.shape[0] # Create a distance matrix dp = np.zeros((len_a + 1, len_b + 1), dtype=np.int32) # Initialize the distance matrix for i in range(len_a + 1): dp[i, 0] = i # Deletion cost for j in range(len_b + 1): dp[0, j] = j # Insertion cost # Compute the Levenshtein distance for i in range(1, len_a + 1): for j in range(1, len_b + 1): cost = 0 if a[i - 1] == b[j - 1] else 1 dp[i, j] = min( dp[i - 1, j] + 1, # Deletion dp[i, j - 1] + 1, # Insertion dp[i - 1, j - 1] + cost # Substitution ) # Check for swap (only if i and j are greater than 1) if i > 1 and j > 1 and a[i - 1] == b[j - 2] and a[i - 2] == b[j - 1]: dp[i, j] = min(dp[i, j], dp[i - 2, j - 2] + 2) # Swap cost return dp[len_a, len_b] # Example usage if __name__ == "__main__": arr1 = np.array([1, 2, 3, 4]) arr2 = np.array([1, 3, 2, 4]) distance = levenshtein(arr1, arr2) print("Levenshtein distance:", distance) |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import numpy as np from numba import njit @njit def levenshtein(a: np.ndarray, b: np.ndarray) -> int: # Lengths of the input arrays len_a = a.shape[0] len_b = b.shape[0] # Create a distance matrix dp = np.zeros((len_a + 1, len_b + 1), dtype=np.int32) # Initialize the distance matrix for i in range(len_a + 1): dp[i, 0] = i # Deletion cost for j in range(len_b + 1): dp[0, j] = j # Insertion cost # Compute the Levenshtein distance for i in range(1, len_a + 1): for j in range(1, len_b + 1): cost = 0 if a[i - 1] == b[j - 1] else 1 dp[i, j] = min( dp[i - 1, j] + 1, # Deletion dp[i, j - 1] + 1, # Insertion dp[i - 1, j - 1] + cost # Substitution ) # Check for swap (only if i and j are greater than 1) if i > 1 and j > 1 and a[i - 1] == b[j - 2] and a[i - 2] == b[j - 1]: dp[i, j] = min(dp[i, j], dp[i - 2, j - 2] + 2) # Swap cost return dp[len_a, len_b] # Example usage if __name__ == "__main__": arr1 = np.array([1, 2, 3, 4]) arr2 = np.array([1, 3, 2, 4]) distance = levenshtein(arr1, arr2) print("Levenshtein distance:", distance) answer = levenshtein(np.array([3, 5, 2, 4, 8, 7]), np.array([3, 4, 2, 4, 8, 7, 9])) expected = 3 assert answer == expected, f'Wrong answer; got {answer} instead of {expected}' print('All tests passed') |
Levenshtein distance: 2
Traceback (most recent call last):
File "/usr/src/app/main.py", line 49, in <module>
assert answer == expected, f'Wrong answer; got {answer} instead of {expected}'
AssertionError: Wrong answer; got 2 instead of 3
Testing if the previous output contains the string All tests passed
: False
Testing if the previous output contains the string njit
: True
Testing if the previous output contains the string nopython
: False
Testing if the previous output contains the string import numba
: False
Testing if the previous output contains the string from numba
: True