{"id":1161047,"date":"2025-01-13T19:12:07","date_gmt":"2025-01-13T11:12:07","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1161047.html"},"modified":"2025-01-13T19:12:09","modified_gmt":"2025-01-13T11:12:09","slug":"%e5%8d%b7%e7%a7%af%e6%98%af%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e7%9a%84python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1161047.html","title":{"rendered":"\u5377\u79ef\u662f\u5982\u4f55\u5b9e\u73b0\u7684python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25202418\/cc034545-fb5a-4171-a237-8a2479b92dc5.webp\" alt=\"\u5377\u79ef\u662f\u5982\u4f55\u5b9e\u73b0\u7684python\" \/><\/p>\n<p><p> \u5377\u79ef\u5728Python\u4e2d\u5b9e\u73b0\u4e3b\u8981\u6709\u51e0\u79cd\u65b9\u6cd5\uff1a<strong>\u4f7f\u7528NumPy\u8fdb\u884c\u624b\u52a8\u5b9e\u73b0\u3001\u5229\u7528SciPy\u5e93\u4e2d\u7684\u4fe1\u53f7\u5904\u7406\u6a21\u5757\u3001\u4ee5\u53ca\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u5982TensorFlow\u6216PyTorch\u7b49<\/strong>\u3002\u5176\u4e2d\uff0c\u4f7f\u7528NumPy\u8fdb\u884c\u624b\u52a8\u5b9e\u73b0\u662f\u4e00\u79cd\u57fa\u7840\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5e2e\u52a9\u7406\u89e3\u5377\u79ef\u64cd\u4f5c\u7684\u57fa\u672c\u539f\u7406\uff0c\u800c\u5229\u7528SciPy\u548c\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u5219\u80fd\u591f\u66f4\u9ad8\u6548\u5730\u5b8c\u6210\u66f4\u590d\u6742\u7684\u5377\u79ef\u64cd\u4f5c\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\uff0c\u5373\u4f7f\u7528NumPy\u624b\u52a8\u5b9e\u73b0\u5377\u79ef\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5377\u79ef\u7684\u57fa\u672c\u6982\u5ff5<\/h3>\n<\/p>\n<p><p>\u5377\u79ef\u662f\u4e00\u79cd\u6570\u5b66\u8fd0\u7b97\uff0c\u901a\u5e38\u7528\u4e8e\u4fe1\u53f7\u5904\u7406\u3001\u56fe\u50cf\u5904\u7406\u3001\u8ba1\u7b97\u673a\u89c6\u89c9\u7b49\u9886\u57df\u3002\u5728\u56fe\u50cf\u5904\u7406\u9886\u57df\uff0c\u5377\u79ef\u64cd\u4f5c\u53ef\u4ee5\u7528\u6765\u63d0\u53d6\u56fe\u50cf\u7684\u7279\u5f81\uff0c\u5982\u8fb9\u7f18\u3001\u89d2\u70b9\u7b49\u3002\u5377\u79ef\u7684\u57fa\u672c\u601d\u60f3\u662f\u901a\u8fc7\u4e00\u4e2a\u5c0f\u7684\u6ee4\u6ce2\u5668\uff08\u6216\u79f0\u4e3a\u6838\uff09\u5728\u56fe\u50cf\u4e0a\u6ed1\u52a8\uff0c\u8ba1\u7b97\u6ee4\u6ce2\u5668\u4e0e\u56fe\u50cf\u5c40\u90e8\u533a\u57df\u7684\u52a0\u6743\u548c\uff0c\u4ece\u800c\u5f97\u5230\u4e00\u4e2a\u65b0\u7684\u8f93\u51fa\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528NumPy\u624b\u52a8\u5b9e\u73b0\u5377\u79ef<\/h3>\n<\/p>\n<p><h4>1\u3001\u4e8c\u7ef4\u5377\u79ef\u7684\u57fa\u672c\u6b65\u9aa4<\/h4>\n<\/p>\n<p><p>\u4e8c\u7ef4\u5377\u79ef\u64cd\u4f5c\u7684\u57fa\u672c\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u9009\u62e9\u4e00\u4e2a\u5377\u79ef\u6838\uff08\u6ee4\u6ce2\u5668\uff09\uff0c\u901a\u5e38\u662f\u4e00\u4e2a\u5c0f\u77e9\u9635\u3002<\/li>\n<li>\u5c06\u5377\u79ef\u6838\u4e0e\u8f93\u5165\u56fe\u50cf\u7684\u5c40\u90e8\u533a\u57df\u8fdb\u884c\u9010\u5143\u7d20\u76f8\u4e58\u3002<\/li>\n<li>\u5c06\u76f8\u4e58\u7684\u7ed3\u679c\u6c42\u548c\uff0c\u5f97\u5230\u4e00\u4e2a\u8f93\u51fa\u503c\u3002<\/li>\n<li>\u5c06\u5377\u79ef\u6838\u5728\u56fe\u50cf\u4e0a\u6ed1\u52a8\uff0c\u91cd\u590d\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u76f4\u5230\u904d\u5386\u6574\u4e2a\u56fe\u50cf\u3002<\/li>\n<\/ol>\n<p><h4>2\u3001\u4ee3\u7801\u5b9e\u73b0<\/h4>\n<\/p>\n<p><p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528NumPy\u5b9e\u73b0\u4e8c\u7ef4\u5377\u79ef\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>def convolve2d(image, kernel):<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    \u8fdb\u884c2D\u5377\u79ef\u64cd\u4f5c\u3002<\/p>\n<p>    \u53c2\u6570:<\/p>\n<p>    image -- \u8f93\u5165\u7684\u4e8c\u7ef4\u56fe\u50cf\u77e9\u9635<\/p>\n<p>    kernel -- \u5377\u79ef\u6838\u77e9\u9635<\/p>\n<p>    \u8fd4\u56de:<\/p>\n<p>    result -- \u7ecf\u8fc7\u5377\u79ef\u64cd\u4f5c\u540e\u7684\u56fe\u50cf<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    # \u83b7\u53d6\u56fe\u50cf\u548c\u5377\u79ef\u6838\u7684\u5f62\u72b6<\/p>\n<p>    image_height, image_width = image.shape<\/p>\n<p>    kernel_height, kernel_width = kernel.shape<\/p>\n<p>    # \u8ba1\u7b97\u8f93\u51fa\u56fe\u50cf\u7684\u5f62\u72b6<\/p>\n<p>    output_height = image_height - kernel_height + 1<\/p>\n<p>    output_width = image_width - kernel_width + 1<\/p>\n<p>    # \u521b\u5efa\u8f93\u51fa\u56fe\u50cf\u77e9\u9635<\/p>\n<p>    result = np.zeros((output_height, output_width))<\/p>\n<p>    # \u8fdb\u884c\u5377\u79ef\u64cd\u4f5c<\/p>\n<p>    for i in range(output_height):<\/p>\n<p>        for j in range(output_width):<\/p>\n<p>            # \u63d0\u53d6\u56fe\u50cf\u7684\u5c40\u90e8\u533a\u57df<\/p>\n<p>            region = image[i:i+kernel_height, j:j+kernel_width]<\/p>\n<p>            # \u9010\u5143\u7d20\u76f8\u4e58\u5e76\u6c42\u548c<\/p>\n<p>            result[i, j] = np.sum(region * kernel)<\/p>\n<p>    return result<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>if __name__ == &quot;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&quot;:<\/p>\n<p>    # \u8f93\u5165\u56fe\u50cf<\/p>\n<p>    image = np.array([[1, 2, 3, 0],<\/p>\n<p>                      [4, 5, 6, 1],<\/p>\n<p>                      [7, 8, 9, 2],<\/p>\n<p>                      [0, 1, 2, 3]])<\/p>\n<p>    # \u5377\u79ef\u6838<\/p>\n<p>    kernel = np.array([[1, 0],<\/p>\n<p>                       [0, -1]])<\/p>\n<p>    # \u8fdb\u884c\u5377\u79ef<\/p>\n<p>    output = convolve2d(image, kernel)<\/p>\n<p>    print(&quot;\u5377\u79ef\u7ed3\u679c\uff1a&quot;)<\/p>\n<p>    print(output)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a<code>convolve2d<\/code>\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u53d7\u8f93\u5165\u56fe\u50cf\u548c\u5377\u79ef\u6838\u4f5c\u4e3a\u53c2\u6570\uff0c\u8fd4\u56de\u7ecf\u8fc7\u5377\u79ef\u64cd\u4f5c\u540e\u7684\u56fe\u50cf\u3002\u5377\u79ef\u64cd\u4f5c\u901a\u8fc7\u53cc\u91cd\u5faa\u73af\u904d\u5386\u56fe\u50cf\u7684\u6bcf\u4e00\u4e2a\u5c40\u90e8\u533a\u57df\uff0c\u5e76\u8ba1\u7b97\u9010\u5143\u7d20\u76f8\u4e58\u7684\u548c\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001SciPy\u5e93\u4e2d\u7684\u5377\u79ef\u5b9e\u73b0<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528scipy.signal.convolve2d\u51fd\u6570<\/h4>\n<\/p>\n<p><p>SciPy\u5e93\u4e2d\u7684<code>scipy.signal<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u4e2a\u65b9\u4fbf\u7684\u51fd\u6570<code>convolve2d<\/code>\uff0c\u53ef\u4ee5\u7528\u4e8e\u4e8c\u7ef4\u5377\u79ef\u64cd\u4f5c\u3002\u8be5\u51fd\u6570\u4e0d\u4ec5\u652f\u6301\u7b80\u5355\u7684\u5377\u79ef\u64cd\u4f5c\uff0c\u8fd8\u652f\u6301\u591a\u79cd\u8fb9\u754c\u5904\u7406\u65b9\u5f0f\u548c\u5377\u79ef\u6a21\u5f0f\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4ee3\u7801\u793a\u4f8b<\/h4>\n<\/p>\n<p><p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528<code>scipy.signal.convolve2d<\/code>\u51fd\u6570\u5b9e\u73b0\u4e8c\u7ef4\u5377\u79ef\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>from scipy.signal import convolve2d<\/p>\n<h2><strong>\u8f93\u5165\u56fe\u50cf<\/strong><\/h2>\n<p>image = np.array([[1, 2, 3, 0],<\/p>\n<p>                  [4, 5, 6, 1],<\/p>\n<p>                  [7, 8, 9, 2],<\/p>\n<p>                  [0, 1, 2, 3]])<\/p>\n<h2><strong>\u5377\u79ef\u6838<\/strong><\/h2>\n<p>kernel = np.array([[1, 0],<\/p>\n<p>                   [0, -1]])<\/p>\n<h2><strong>\u8fdb\u884c\u5377\u79ef<\/strong><\/h2>\n<p>output = convolve2d(image, kernel, mode=&#39;valid&#39;)<\/p>\n<p>print(&quot;\u5377\u79ef\u7ed3\u679c\uff1a&quot;)<\/p>\n<p>print(output)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86<code>scipy.signal.convolve2d<\/code>\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u53d7\u8f93\u5165\u56fe\u50cf\u3001\u5377\u79ef\u6838\u3001\u5377\u79ef\u6a21\u5f0f\u7b49\u53c2\u6570\uff0c\u8fd4\u56de\u7ecf\u8fc7\u5377\u79ef\u64cd\u4f5c\u540e\u7684\u56fe\u50cf\u3002<code>mode<\/code>\u53c2\u6570\u6307\u5b9a\u5377\u79ef\u6a21\u5f0f\uff0c\u4f8b\u5982<code>&#39;valid&#39;<\/code>\u8868\u793a\u4ec5\u8fd4\u56de\u5b8c\u5168\u88ab\u5377\u79ef\u6838\u8986\u76d6\u7684\u90e8\u5206\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u4e2d\u7684\u5377\u79ef\u5b9e\u73b0<\/h3>\n<\/p>\n<p><h4>1\u3001TensorFlow\u4e2d\u7684\u5377\u79ef<\/h4>\n<\/p>\n<p><p>TensorFlow\u662f\u4e00\u4e2a\u5e7f\u6cdb\u4f7f\u7528\u7684\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\uff0c\u63d0\u4f9b\u4e86\u591a\u79cd\u5377\u79ef\u64cd\u4f5c\u51fd\u6570\uff0c\u5982<code>tf.nn.conv2d<\/code>\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528TensorFlow\u5b9e\u73b0\u4e8c\u7ef4\u5377\u79ef\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tensorflow as tf<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u8f93\u5165\u56fe\u50cf<\/strong><\/h2>\n<p>image = np.array([[[[1], [2], [3], [0]],<\/p>\n<p>                   [[4], [5], [6], [1]],<\/p>\n<p>                   [[7], [8], [9], [2]],<\/p>\n<p>                   [[0], [1], [2], [3]]]], dtype=np.float32)<\/p>\n<h2><strong>\u5377\u79ef\u6838<\/strong><\/h2>\n<p>kernel = np.array([[[[1]], [[0]]],<\/p>\n<p>                   [[[0]], [[-1]]]], dtype=np.float32)<\/p>\n<h2><strong>\u8fdb\u884c\u5377\u79ef<\/strong><\/h2>\n<p>output = tf.nn.conv2d(image, kernel, strides=[1, 1, 1, 1], padding=&#39;VALID&#39;)<\/p>\n<p>print(&quot;\u5377\u79ef\u7ed3\u679c\uff1a&quot;)<\/p>\n<p>print(output.numpy())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86TensorFlow\u7684<code>tf.nn.conv2d<\/code>\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u53d7\u8f93\u5165\u56fe\u50cf\u3001\u5377\u79ef\u6838\u3001\u6b65\u957f\u548c\u586b\u5145\u65b9\u5f0f\u7b49\u53c2\u6570\uff0c\u8fd4\u56de\u7ecf\u8fc7\u5377\u79ef\u64cd\u4f5c\u540e\u7684\u56fe\u50cf\u3002\u8f93\u5165\u56fe\u50cf\u548c\u5377\u79ef\u6838\u90fd\u9700\u8981\u8f6c\u6362\u4e3a\u56db\u7ef4\u5f20\u91cf\u3002<\/p>\n<\/p>\n<p><h4>2\u3001PyTorch\u4e2d\u7684\u5377\u79ef<\/h4>\n<\/p>\n<p><p>PyTorch\u662f\u53e6\u4e00\u4e2a\u6d41\u884c\u7684\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\uff0c\u540c\u6837\u63d0\u4f9b\u4e86\u591a\u79cd\u5377\u79ef\u64cd\u4f5c\u51fd\u6570\uff0c\u5982<code>torch.nn.functional.conv2d<\/code>\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528PyTorch\u5b9e\u73b0\u4e8c\u7ef4\u5377\u79ef\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import torch<\/p>\n<p>import torch.nn.functional as F<\/p>\n<h2><strong>\u8f93\u5165\u56fe\u50cf<\/strong><\/h2>\n<p>image = torch.tensor([[[[1, 2, 3, 0],<\/p>\n<p>                        [4, 5, 6, 1],<\/p>\n<p>                        [7, 8, 9, 2],<\/p>\n<p>                        [0, 1, 2, 3]]]], dtype=torch.float32)<\/p>\n<h2><strong>\u5377\u79ef\u6838<\/strong><\/h2>\n<p>kernel = torch.tensor([[[[1, 0],<\/p>\n<p>                         [0, -1]]]], dtype=torch.float32)<\/p>\n<h2><strong>\u8fdb\u884c\u5377\u79ef<\/strong><\/h2>\n<p>output = F.conv2d(image, kernel, stride=1, padding=0)<\/p>\n<p>print(&quot;\u5377\u79ef\u7ed3\u679c\uff1a&quot;)<\/p>\n<p>print(output)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86PyTorch\u7684<code>torch.nn.functional.conv2d<\/code>\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u53d7\u8f93\u5165\u56fe\u50cf\u3001\u5377\u79ef\u6838\u3001\u6b65\u957f\u548c\u586b\u5145\u65b9\u5f0f\u7b49\u53c2\u6570\uff0c\u8fd4\u56de\u7ecf\u8fc7\u5377\u79ef\u64cd\u4f5c\u540e\u7684\u56fe\u50cf\u3002\u8f93\u5165\u56fe\u50cf\u548c\u5377\u79ef\u6838\u90fd\u9700\u8981\u8f6c\u6362\u4e3a\u56db\u7ef4\u5f20\u91cf\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5377\u79ef\u64cd\u4f5c\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><h4>1\u3001\u56fe\u50cf\u8fc7\u6ee4<\/h4>\n<\/p>\n<p><p>\u5377\u79ef\u64cd\u4f5c\u5e38\u7528\u4e8e\u56fe\u50cf\u8fc7\u6ee4\uff0c\u4f8b\u5982\u8fb9\u7f18\u68c0\u6d4b\u3001\u6a21\u7cca\u5904\u7406\u3001\u9510\u5316\u5904\u7406\u7b49\u3002\u901a\u8fc7\u9009\u62e9\u4e0d\u540c\u7684\u5377\u79ef\u6838\uff0c\u53ef\u4ee5\u5b9e\u73b0\u4e0d\u540c\u7684\u56fe\u50cf\u8fc7\u6ee4\u6548\u679c\u3002\u4f8b\u5982\uff0c\u4f7f\u7528Sobel\u7b97\u5b50\u8fdb\u884c\u8fb9\u7f18\u68c0\u6d4b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>from scipy.signal import convolve2d<\/p>\n<h2><strong>\u8f93\u5165\u56fe\u50cf<\/strong><\/h2>\n<p>image = np.array([[1, 2, 3, 0],<\/p>\n<p>                  [4, 5, 6, 1],<\/p>\n<p>                  [7, 8, 9, 2],<\/p>\n<p>                  [0, 1, 2, 3]])<\/p>\n<h2><strong>Sobel\u7b97\u5b50<\/strong><\/h2>\n<p>sobel_x = np.array([[-1, 0, 1],<\/p>\n<p>                    [-2, 0, 2],<\/p>\n<p>                    [-1, 0, 1]])<\/p>\n<p>sobel_y = np.array([[-1, -2, -1],<\/p>\n<p>                    [0, 0, 0],<\/p>\n<p>                    [1, 2, 1]])<\/p>\n<h2><strong>\u8fdb\u884c\u5377\u79ef<\/strong><\/h2>\n<p>edge_x = convolve2d(image, sobel_x, mode=&#39;valid&#39;)<\/p>\n<p>edge_y = convolve2d(image, sobel_y, mode=&#39;valid&#39;)<\/p>\n<h2><strong>\u8ba1\u7b97\u8fb9\u7f18\u5f3a\u5ea6<\/strong><\/h2>\n<p>edges = np.sqrt(edge_x&lt;strong&gt;2 + edge_y&lt;\/strong&gt;2)<\/p>\n<p>print(&quot;\u8fb9\u7f18\u68c0\u6d4b\u7ed3\u679c\uff1a&quot;)<\/p>\n<p>print(edges)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u7279\u5f81\u63d0\u53d6<\/h4>\n<\/p>\n<p><p>\u5377\u79ef\u64cd\u4f5c\u8fd8\u7528\u4e8e\u7279\u5f81\u63d0\u53d6\uff0c\u4f8b\u5982\u5728\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\uff08CNN\uff09\u4e2d\uff0c\u901a\u8fc7\u591a\u5c42\u5377\u79ef\u63d0\u53d6\u56fe\u50cf\u7684\u9ad8\u7ea7\u7279\u5f81\u3002\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u5728\u56fe\u50cf\u5206\u7c7b\u3001\u76ee\u6807\u68c0\u6d4b\u3001\u56fe\u50cf\u5206\u5272\u7b49\u4efb\u52a1\u4e2d\u8868\u73b0\u51fa\u8272\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5377\u79ef\u5728Python\u4e2d\u7684\u5b9e\u73b0\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec<strong>\u4f7f\u7528NumPy\u624b\u52a8\u5b9e\u73b0\u3001\u5229\u7528SciPy\u5e93\u4e2d\u7684\u4fe1\u53f7\u5904\u7406\u6a21\u5757\u3001\u4ee5\u53ca\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u5982TensorFlow\u6216PyTorch<\/strong>\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u7f3a\u70b9\uff0c\u9009\u62e9\u9002\u5408\u7684\u5b9e\u73b0\u65b9\u5f0f\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\u548c\u9700\u6c42\u3002\u901a\u8fc7\u5bf9\u5377\u79ef\u64cd\u4f5c\u7684\u6df1\u5165\u7406\u89e3\u548c\u5b9e\u8df5\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u5e94\u7528\u5377\u79ef\u6280\u672f\u89e3\u51b3\u5404\u79cd\u5b9e\u9645\u95ee\u9898\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5377\u79ef\u5728Python\u4e2d\u53ef\u4ee5\u901a\u8fc7\u54ea\u4e9b\u5e93\u5b9e\u73b0\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u5377\u79ef\u53ef\u4ee5\u901a\u8fc7\u591a\u4e2a\u5e93\u5b9e\u73b0\uff0c\u6700\u5e38\u7528\u7684\u6709NumPy\u548cSciPy\u3002NumPy\u63d0\u4f9b\u4e86\u57fa\u672c\u7684\u5377\u79ef\u529f\u80fd\uff0c\u9002\u5408\u5904\u7406\u4e00\u7ef4\u548c\u4e8c\u7ef4\u6570\u7ec4\uff1b\u800cSciPy\u5219\u63d0\u4f9b\u4e86\u66f4\u591a\u9ad8\u7ea7\u529f\u80fd\uff0c\u6bd4\u5982\u4fe1\u53f7\u5904\u7406\u4e2d\u7684\u5377\u79ef\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u5982TensorFlow\u548cPyTorch\u4e5f\u5305\u542b\u4e86\u9ad8\u6548\u7684\u5377\u79ef\u5b9e\u73b0\uff0c\u9002\u5408\u7528\u4e8e\u795e\u7ecf\u7f51\u7edc\u6a21\u578b\u7684\u6784\u5efa\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528NumPy\u5b9e\u73b0\u5377\u79ef\u64cd\u4f5c\uff1f<\/strong><br \/>\u4f7f\u7528NumPy\u5b9e\u73b0\u5377\u79ef\u64cd\u4f5c\u975e\u5e38\u7b80\u5355\u3002\u53ef\u4ee5\u4f7f\u7528<code>numpy.convolve()<\/code>\u51fd\u6570\u8fdb\u884c\u4e00\u7ef4\u5377\u79ef\uff0c\u6216\u4f7f\u7528<code>scipy.signal.convolve2d()<\/code>\u8fdb\u884c\u4e8c\u7ef4\u5377\u79ef\u3002\u9700\u8981\u51c6\u5907\u597d\u8f93\u5165\u4fe1\u53f7\u548c\u5377\u79ef\u6838\uff0c\u7136\u540e\u8c03\u7528\u76f8\u5e94\u7684\u51fd\u6570\u5373\u53ef\u3002\u5bf9\u4e8e\u4e00\u7ef4\u5377\u79ef\uff0c\u8fd4\u56de\u7684\u7ed3\u679c\u662f\u8f93\u5165\u4fe1\u53f7\u548c\u5377\u79ef\u6838\u7684\u7ebf\u6027\u7ec4\u5408\uff0c\u800c\u4e8c\u7ef4\u5377\u79ef\u5219\u5904\u7406\u56fe\u50cf\u6570\u636e\uff0c\u8f93\u51fa\u7ecf\u8fc7\u5377\u79ef\u5904\u7406\u7684\u56fe\u50cf\u3002<\/p>\n<p><strong>\u5728\u5377\u79ef\u64cd\u4f5c\u4e2d\uff0c\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u5377\u79ef\u6838\uff1f<\/strong><br \/>\u9009\u62e9\u5408\u9002\u7684\u5377\u79ef\u6838\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\u3002\u5e38\u89c1\u7684\u5377\u79ef\u6838\u6709\u8fb9\u7f18\u68c0\u6d4b\u3001\u6a21\u7cca\u3001\u9510\u5316\u7b49\u3002\u53ef\u4ee5\u6839\u636e\u5904\u7406\u4efb\u52a1\u7684\u9700\u6c42\u6765\u9009\u62e9\u6216\u81ea\u5b9a\u4e49\u5377\u79ef\u6838\u3002\u4f8b\u5982\uff0c\u5728\u56fe\u50cf\u5904\u7406\u4e2d\u7684\u8fb9\u7f18\u68c0\u6d4b\uff0c\u5e38\u7528\u7684\u5377\u79ef\u6838\u5305\u62ecSobel\u548cLaplacian\uff1b\u800c\u5728\u4fe1\u53f7\u5904\u7406\u4e2d\uff0c\u5e73\u6ed1\u6216\u4f4e\u901a\u6ee4\u6ce2\u7684\u5377\u79ef\u6838\u5219\u53ef\u4ee5\u7528\u6765\u51cf\u5c11\u566a\u58f0\u3002\u8c03\u6574\u5377\u79ef\u6838\u7684\u5927\u5c0f\u548c\u6743\u91cd\u4e5f\u4f1a\u5f71\u54cd\u6700\u7ec8\u7ed3\u679c\uff0c\u56e0\u6b64\u9700\u8981\u6839\u636e\u5b9e\u9645\u6548\u679c\u8fdb\u884c\u5b9e\u9a8c\u548c\u8c03\u6574\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5377\u79ef\u5728Python\u4e2d\u5b9e\u73b0\u4e3b\u8981\u6709\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528NumPy\u8fdb\u884c\u624b\u52a8\u5b9e\u73b0\u3001\u5229\u7528SciPy\u5e93\u4e2d\u7684\u4fe1\u53f7\u5904\u7406\u6a21\u5757\u3001\u4ee5\u53ca\u4f7f\u7528 [&hellip;]","protected":false},"author":3,"featured_media":1161053,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1161047"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1161047"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1161047\/revisions"}],"predecessor-version":[{"id":1161055,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1161047\/revisions\/1161055"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1161053"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1161047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1161047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1161047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}