fork(1) download
  1. # your code goes here
  2. from numba import cuda
  3. import numpy as np
  4. import math
  5. data = np.load('example_data.npy')
  6. def ridge_detection(f, thres):
  7. count = np.zeros(f.shape)
  8. for i in range(len(f)):
  9. for j in range(len(f[i])):
  10. if (
  11. i > 0
  12. and j > 0
  13. and i < (len(f) - 1)
  14. and j < (len(f[i]) - 1)
  15. and f[i, j] > thres
  16. and ~np.isnan(f[i, j])
  17. ):
  18. step_i = i
  19. step_j = j
  20. for k in range(1000):
  21. if (
  22. step_i == 0
  23. or step_j == 0
  24. or step_i == (len(f) - 1)
  25. or step_j == (len(f[i]) - 1)
  26. ):
  27. break
  28. index = np.nanargmax(
  29. f[step_i - 1 : step_i + 2, step_j - 1 : step_j + 2].data
  30. )
  31. vmax = np.nanmax(
  32. f[step_i - 1 : step_i + 2, step_j - 1 : step_j + 2].data
  33. )
  34. if index == 4 or vmax == f[step_i, step_j] or np.isnan(vmax):
  35. break
  36. row = int(index / 3)
  37. col = index % 3
  38. count[step_i - 1 + row, step_j - 1 + col] += 1
  39. step_i = step_i - 1 + row
  40. step_j = step_j - 1 + col
  41. %%time
  42. results = ridge_detection(data, 0)
  43. return count
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Traceback (most recent call last):
  File "/usr/lib/python3.9/py_compile.py", line 144, in compile
    code = loader.source_to_code(source_bytes, dfile or file,
  File "<frozen importlib._bootstrap_external>", line 918, in source_to_code
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "./prog.py", line 41
    %%time
    ^
SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.9/py_compile.py", line 150, in compile
    raise py_exc
py_compile.PyCompileError:   File "./prog.py", line 41
    %%time
    ^
SyntaxError: invalid syntax

stdout
Standard output is empty