Advertisement
Guest User

Untitled

a guest
Oct 9th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 3,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "import numba\n",
  10. "import numpy as np\n",
  11. "\n",
  12. "def gather_from_detector():\n",
  13. " return np.random.random((1000, 1000))\n",
  14. "\n",
  15. "@numba.jit\n",
  16. "def smooth(x):\n",
  17. " out = np.empty_like(x)\n",
  18. " for i in range(1, x.shape[0] - 1):\n",
  19. " for j in range(1, x.shape[1] - 1):\n",
  20. " out[i, j] = (x[i + -1, j + -1] + x[i + -1, j + 0] + x[i + -1, j + 1] +\n",
  21. " x[i + 0, j + -1] + x[i + 0, j + 0] + x[i + 0, j + 1] +\n",
  22. " x[i + 1, j + -1] + x[i + 1, j + 0] + x[i + 1, j + 1]) // 9\n",
  23. "\n",
  24. " return out\n",
  25. "\n",
  26. "def save(x, filename):\n",
  27. " pass"
  28. ]
  29. },
  30. {
  31. "cell_type": "code",
  32. "execution_count": 8,
  33. "metadata": {},
  34. "outputs": [
  35. {
  36. "name": "stdout",
  37. "output_type": "stream",
  38. "text": [
  39. "Wall time: 3.17 s\n"
  40. ]
  41. }
  42. ],
  43. "source": [
  44. "%%time\n",
  45. "for i in range(50):\n",
  46. " img = gather_from_detector()\n",
  47. " img = smooth(img)\n",
  48. " img = np.fft.fft2(img)\n",
  49. " save(img, \"file-\" + str(i) + \"-.dat\")"
  50. ]
  51. },
  52. {
  53. "cell_type": "code",
  54. "execution_count": null,
  55. "metadata": {},
  56. "outputs": [],
  57. "source": []
  58. }
  59. ],
  60. "metadata": {
  61. "kernelspec": {
  62. "display_name": "Python 3",
  63. "language": "python",
  64. "name": "python3"
  65. },
  66. "language_info": {
  67. "codemirror_mode": {
  68. "name": "ipython",
  69. "version": 3
  70. },
  71. "file_extension": ".py",
  72. "mimetype": "text/x-python",
  73. "name": "python",
  74. "nbconvert_exporter": "python",
  75. "pygments_lexer": "ipython3",
  76. "version": "3.7.3"
  77. }
  78. },
  79. "nbformat": 4,
  80. "nbformat_minor": 4
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement