{"id":18023,"date":"2025-05-05T11:17:29","date_gmt":"2025-05-05T03:17:29","guid":{"rendered":"https:\/\/www.orczhou.com\/?p=18023"},"modified":"2025-05-05T11:17:29","modified_gmt":"2025-05-05T03:17:29","slug":"understanding-numpy-ndarray-high-dimension","status":"publish","type":"post","link":"https:\/\/www.orczhou.com\/index.php\/2025\/05\/understanding-numpy-ndarray-high-dimension\/","title":{"rendered":"\u7406\u89e3 NumPy \u4e2d\u7684\u9ad8\u7ef4\u6570\u7ec4"},"content":{"rendered":"<div id=\"tocer-1\" class=\"tocer tocer-pos-flt-e\"><div class=\"tocer-toc\"><header class=\"tocer-header\"><h2 class=\"tocer-title\">\u76ee\u5f55<\/h2>\n<\/header>\n<ul class=\"tocer-list tocer-adv tocer-sp-os-bf tocer-st-ctrs-dec tocer-lvl1\"><li><div><a href=\"#tocer-heading-1\">\u95ee\u9898<\/a><\/div><\/li>\n<li><div><a href=\"#tocer-heading-2\">\u6587\u6863\u4e2d\u5bf9\u4e8e\u9ad8\u7ef4\u6570\u7ec4\u7406\u89e3\u7684\u5efa\u8bae<\/a><\/div><\/li>\n<li><div><a href=\"#tocer-heading-3\">\u4ece 4&#215;5 \u7684\u6570\u7ec4\u5f00\u59cb<\/a><\/div><\/li>\n<li><div><a href=\"#tocer-heading-4\">\u518d\u8003\u8651 3x4x5 \u7684\u6570\u7ec4<\/a><\/div><\/li>\n<li><div><a href=\"#tocer-heading-5\">\u8003\u8651 2x3x4x5 \u7684\u6570\u7ec4<\/a><\/div><\/li>\n<li><div><a href=\"#tocer-heading-6\">\u56de\u5230\u524d\u9762\u7684\u95ee\u9898<\/a><\/div><\/li>\n<li><div><a href=\"#tocer-heading-7\">\u6700\u540e<\/a><\/div><\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<p>\u5728\u673a\u5668\u5b66\u4e60\u4e2d\u5927\u91cf\u7684\u4f7f\u7528<code>NumPy<\/code>\u4f5c\u4e3a\u5176\u57fa\u7840\u7684\u6570\u636e\u7ed3\u6784\uff0c<code>ndarray<\/code>\u662f<code>NumPy<\/code>\u7684\u6838\u5fc3\u6570\u636e\u5bf9\u8c61\u3002\u5bf9\u4e8e<code>ndarray<\/code>\u9ad8\u7ef4\u6570\u7ec4\u7684\u4e00\u4e2a\u975e\u5e38\u5bb9\u6613\u4ea7\u751f\u7684\u8bef\u89e3\u662f\uff0c\u4f7f\u7528\u6570\u5b66\u4e2d\u7684\u77e9\u9635\uff08\u6216\u8005\u53eb\u201c\u884c\u5217\u5f0f\u201d\uff09\u6982\u5ff5\u53bb\u5c1d\u8bd5\u7406\u89e3\u66f4\u9ad8\u7ef4\u7684\u573a\u666f\uff0c\u6216\u8005\u4f7f\u7528\u66f4\u9ad8\u7ef4\u7a7a\u95f4\u53bb\u7406\u89e3\uff0c\u8fd9\u6837\u90fd\u4f1a\u5bfc\u81f4\u96be\u4ee5\u8f83\u597d\u7684\u7406\u89e3\u66f4\u9ad8\u7ef4\uff085\u62166\u7ef4\uff09\u7684\u6570\u7ec4\u3002\u672c\u6587\u4f7f\u7528\u8f83\u4e3a\u76f4\u89c2\u7684\u793a\u4f8b\u548c\u53ef\u89c6\u5316\u7684\u5c55\u793a\uff0c\u66f4\u4e3a\u201c\u6807\u51c6\u201d\uff08\u6587\u6863\u63a8\u8350\u7684\uff09\u7684\u65b9\u5f0f\u53bb\u7406\u89e3<code>ndarray<\/code>\u7684\u66f4\u9ad8\u7ef4\u6570\u7ec4\u3002\u66f4\u591a\u8be6\u7ec6\u5185\u5bb9\uff0c\u53ef\u4ee5\u53c2\u8003\u9605\u8bfb\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.ndarray.html\">numpy.ndarray<\/a><\/code><\/li>\n\n\n\n<li><code><a href=\"https:\/\/numpy.org\/doc\/stable\/user\/absolute_beginners.html\">NumPy: the absolute basics for beginners<\/a><\/code><\/li>\n<\/ul>\n\n\n\n\n\n\n<h3 class=\"wp-block-heading\">\u95ee\u9898<\/h3>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>\u5728\u673a\u5668\u5b66\u4e60\u4e2d\uff0c\u7ecf\u5e38\u8981\u5bf9\u591a\u7ef4\u7684\u6570\u7ec4\u505a\u5404\u79cd\u64cd\u4f5c\u3002\u5bf9\u9ad8\u7ef4\u6570\u7ec4\u5efa\u7acb\u66f4\u597d\u7684\u76f4\u89c9\u7406\u89e3\uff0c\u5219\u6709\u5229\u4e8e\u53bb\u7406\u89e3\u8fd9\u4e9b\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u8003\u8651\u53f3\u4fa7\u7684\u4ee3\u7801\uff0c\u60f3\u4e00\u60f3\u8be5\u4ee3\u7801\u7684\u8f93\u51fa\u662f\u4ec0\u4e48\uff1f<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-code\"><code lang=\"python\" class=\"language-python\">&gt;&gt;&gt; import numpy as np\n&gt;&gt;&gt; np.array([[[1],[2]],[[3],[4]]]).shape\n(\u8003\u8651\u8f93\u51fa\u662f\u4ec0\u4e48)<\/code><\/pre>\n<\/div>\n<\/div>\n\n\n\n<p>\u8981\u56de\u7b54\u8fd9\u4e2a\u95ee\u9898\uff0c\u5219\u9700\u8981\u5efa\u7acb\u5bf9\u4e8e\u591a\u7ef4\u6570\u7ec4\u7ed3\u6784\u7684\u7406\u89e3\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u6587\u6863\u4e2d\u5bf9\u4e8e\u9ad8\u7ef4\u6570\u7ec4\u7406\u89e3\u7684\u5efa\u8bae<\/h3>\n\n\n\n<p>\u5728<code><a href=\"https:\/\/numpy.org\/doc\/stable\/user\/absolute_beginners.html\">NumPy: the absolute basics for beginners<\/a><\/code>\u4e2d\u6709\u5982\u4e0b\u4e00\u6bb5\u8bdd\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>It is familiar practice in mathematics to refer to elements of a matrix by the row index first and the column index second. This happens to be true for two-dimensional arrays, but a better mental model is to think of the column index as coming&nbsp;<em>last<\/em>&nbsp;and the row index as&nbsp;<em>second to last<\/em>. This generalizes to arrays with&nbsp;<em>any<\/em>&nbsp;number of dimensions.<\/p>\n<\/blockquote>\n\n\n\n<p>\u201c\u77e9\u9635\u201d\u662f\u201c\u7ebf\u6027\u4ee3\u6570\u201d\u7684\u4e3b\u8981\u7814\u7a76\u5bf9\u8c61\uff0c\u4e00\u4e2a\\( m \\times n \\)\u7684\u77e9\u9635\u5373\u662f\u4e00\u4e2a\u5e73\u9762\u4e0a\u7684\\( m \\)\u884c\\( m \\)\u5217\u7684\u884c\u5217\u5f0f\u3002\u4e00\u79cd\u5e38\u89c1\u7684\u5411\u9ad8\u7ef4\u6269\u5c55\u7684\u601d\u8003\u65b9\u5f0f\u662f\uff0c\u4f1a\u5c06\u4e09\u7ef4\u6570\u7ec4\u6269\u5c55\u4e3a\u4e09\u7ef4\u7a7a\u95f4\u4e2d\u7684\u6570\u7ec4\u3002\u4f46\uff0c\u8fd9\u6837\u7684\u6269\u5c55\uff0c\u975e\u5e38\u4e0d\u5229\u4e8e\u53bb\u7406\u89e3\u66f4\u9ad8\u7ef4\u7684\u6570\u7ec4\u3002\u8fd9\u91cc\u63d0\u5230\u7684\u65b9\u6848\u662f\u8fd9\u6837\uff1a\u201ca better mental model is to think of the column index as coming\u00a0<em>last<\/em>\u00a0and the row index as\u00a0<em>second to last<\/em>.\u201d\u3002<\/p>\n\n\n\n<p>\u8fd9\u79cd\u7406\u89e3\uff0c\u4e5f\u662f\u672c\u6587\u7684\u6838\u5fc3\uff0c\u6982\u51b5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u603b\u662f\u5c06\u6700\u540e\u4e00\u4e2a\u7ef4\u5ea6\u7406\u89e3\u4e3a\u5217\u7ef4\u5ea6<\/li>\n\n\n\n<li>\u603b\u662f\u5c06\u5012\u6570\u7b2c\u4e8c\u4e2a\u7ef4\u5ea6\u7406\u89e3\u4e3a\u884c\u7ef4\u5ea6<\/li>\n\n\n\n<li>\u5269\u4f59\u7684\u7ef4\u5ea6\uff0c\u5219\u662f\u901a\u8fc7\u5c42\u7684\u65b9\u5f0f\u53bb\u6784\u5efa<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u4ece 4&#215;5 \u7684\u6570\u7ec4\u5f00\u59cb<\/h3>\n\n\n\n<p>\u5148\u901a\u8fc7\u76f4\u89c2\u7684\u4e66\u5199\u8868\u8fbe\uff0c\u770b\u770b\u8fd9\u6837\u7684\u6570\u7ec4\u5e94\u8be5\u662f\u600e\u6837\u7684\u3002<\/p>\n\n\n\n<div class=\"wp-block-columns orczhou_0_8_font_size is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:30%\">\n<p>\u4e00\u822c\u7684\u77e9\u9635\uff08\u884c\u5217\u5f0f\u8868\u793a\uff09\uff1a<\/p>\n\n\n<p>\\begin{bmatrix}<br \/>\n0 &#038; 1 &#038; 2 &#038; 3 &#038; 4 \\\\<br \/>\n5 &#038; 6 &#038; 7 &#038; 8 &#038; 9 \\\\<br \/>\n10 &#038; 11 &#038; 12 &#038; 13 &#038; 14 \\\\<br \/>\n15 &#038; 16 &#038; 17 &#038; 18 &#038; 19 \\\\<br \/>\n\\end{bmatrix}<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:30%\">\n<p>\u672c\u6587\u63a8\u8350\u7684\u7406\u89e3\u65b9\u5f0f\uff1a<\/p>\n\n\n<p>\\[<br \/>\n\\begin{bmatrix}<br \/>\n[0 &#038; 1 &#038; 2 &#038; 3 &#038; 4] \\\\<br \/>\n[5 &#038; 6 &#038; 7 &#038; 8 &#038; 9] \\\\<br \/>\n[10 &#038; 11 &#038; 12 &#038; 13 &#038; 14] \\\\<br \/>\n[15 &#038; 16 &#038; 17 &#038; 18 &#038; 19]<br \/>\n\\end{bmatrix}<br \/>\n\\]<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:40%\">\n<p>numpy\u7684\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"python\" class=\"language-python\">&gt;&gt;&gt; np.arange(20).reshape(4,5)\narray([[ 0,  1,  2,  3,  4],\n       [ 5,  6,  7,  8,  9],\n       [10, 11, 12, 13, 14],\n       [15, 16, 17, 18, 19]])<\/code><\/pre>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><\/div>\n<\/div>\n\n\n\n<p>\u5982\u679c\u6309\u7167\u201c\u77e9\u9635\u201d\u601d\u60f3\u53bb\u7406\u89e3\u8fd9\u4e2a\u77e9\u9635\u5f88\u7b80\u5355\u3002\u4f46\u8fd9\u91cc\uff0c\u6211\u4eec\u91cd\u65b0\u6309\u7167\u4e0a\u8ff0\u7684\u539f\u5219\u53bb\u7406\u89e3\u8fd9\u4e2a\u6570\u7ec4\u3002\u5373\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6700\u540e\u4e00\u4e2a\u7ef4\u5ea6\uff08\u5373\u7b2c\u4e8c\u4e2a\u7ef4\u5ea6\uff09\uff0c\u8be5\u7ef4\u5ea6\u7684\u957f\u5ea6\u662f5\uff0c\u5c06\u5176\u7406\u89e3\u4e3a<strong>\u5217<\/strong>\u7ef4\u5ea6<\/li>\n\n\n\n<li>\u5012\u6570\u7b2c\u4e8c\u4e2a\u7ef4\u5ea6\uff0c\u5373\u7b2c\u4e00\u4e2a\u7ef4\u5ea6\uff0c\u8be5\u7ef4\u5ea6\u7684\u957f\u5ea6\u662f4\uff0c\u5c06\u5176\u7406\u89e3\u4e3a<strong>\u884c<\/strong>\u7ef4\u5ea6<\/li>\n<\/ul>\n\n\n\n<p>\u5f62\u5f0f\u4e0a\uff0c\u8fd9\u4e0e\u4e00\u822c\u7684\u77e9\u9635\uff0c\u662f\u5b8c\u5168\u4e00\u81f4\u7684\u3002\u53ea\u662f\uff0c\u601d\u7ef4\u65b9\u5f0f\uff0c\u53cd\u8fc7\u6765\u4e86\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u518d\u8003\u8651 3x4x5 \u7684\u6570\u7ec4<\/h3>\n\n\n\n<p>\u8fd9\u4e2a\u6570\u7ec4\u5df2\u7ecf\u4e0d\u80fd\u7528\u7b80\u5355\u7684\u5e73\u9762\u8868\u793a\u4e86\uff0c\u8fd9\u91cc\u4f7f\u7528\u4e86\u7b26\u5408\u4e0a\u8ff0\u63cf\u8ff0\u7684\u5f62\u5f0f\u63cf\u8ff0\uff0c\u201c\u5269\u4f59\u7684\u7ef4\u5ea6\uff0c\u5219\u662f\u901a\u8fc7\u5c42\u7684\u65b9\u5f0f\u53bb\u6784\u5efa\u201d\uff0c\u5219\u6709\uff1a<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>\u672c\u6587\u63a8\u8350\u7684\u7406\u89e3\u65b9\u5f0f\uff1a<\/p>\n\n\n<p>\\[<br \/>\n\\begin{array}{r c}<br \/>\n\\text{Layer 1:} &#038;<br \/>\n\\left[<br \/>\n\\begin{array}{c}<br \/>\n[0 &#038; 1 &#038; 2 &#038; 3 &#038; 4] \\\\<br \/>\n[5 &#038; 6 &#038; 7 &#038; 8 &#038; 9] \\\\<br \/>\n[10 &#038; 11 &#038; 12 &#038; 13 &#038; 14] \\\\<br \/>\n[15 &#038; 16 &#038; 17 &#038; 18 &#038; 19] \\\\<br \/>\n\\end{array}<br \/>\n\\right]<br \/>\n\\\\<br \/>\n\\text{Layer 2:} &#038;<br \/>\n\\left[<br \/>\n\\begin{array}{c}<br \/>\n[20 &#038; 21 &#038; 22 &#038; 23 &#038; 24] \\\\<br \/>\n[25 &#038; 26 &#038; 27 &#038; 28 &#038; 29] \\\\<br \/>\n[30 &#038; 31 &#038; 32 &#038; 33 &#038; 34] \\\\<br \/>\n[35 &#038; 36 &#038; 37 &#038; 38 &#038; 39] \\\\<br \/>\n\\end{array}<br \/>\n\\right]<br \/>\n\\\\<br \/>\n\\text{Layer 3:} &#038;<br \/>\n\\left[<br \/>\n\\begin{array}{c}<br \/>\n[40 &#038; 41 &#038; 42 &#038; 43 &#038; 44] \\\\<br \/>\n[45 &#038; 46 &#038; 47 &#038; 48 &#038; 49] \\\\<br \/>\n[50 &#038; 51 &#038; 52 &#038; 53 &#038; 54] \\\\<br \/>\n[55 &#038; 56 &#038; 57 &#038; 58 &#038; 59] \\\\<br \/>\n\\end{array}<br \/>\n\\right]<br \/>\n\\end{array}<br \/>\n\\]<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-code\"><code lang=\"python\" class=\"language-python\">&gt;&gt;&gt; np.arange(60).reshape(3,4,5)\narray([[[ 0,  1,  2,  3,  4],\n        [ 5,  6,  7,  8,  9],\n        [10, 11, 12, 13, 14],\n        [15, 16, 17, 18, 19]],\n\n       [[20, 21, 22, 23, 24],\n        [25, 26, 27, 28, 29],\n        [30, 31, 32, 33, 34],\n        [35, 36, 37, 38, 39]],\n\n       [[40, 41, 42, 43, 44],\n        [45, 46, 47, 48, 49],\n        [50, 51, 52, 53, 54],\n        [55, 56, 57, 58, 59]]])<\/code><\/pre>\n<\/div>\n<\/div>\n\n\n\n<p>\u8fd9\u65f6\uff0c\u77e9\u9635\u7684\u60f3\u6cd5\u5c31\u4e0d\u592a\u597d\u7528\u4e86\u3002\u8fd9\u91cc\u7ee7\u7eed\u6309\u7167\u4e0a\u9762\u7684\u539f\u5219\uff0c\u8003\u8651\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6700\u540e\u4e00\u4e2a\u7ef4\u5ea6\uff0c\u5373\u8fd9\u91cc\u7684\u7b2c\u4e09\u4e2a\u7ef4\u5ea6\uff0c\u8be5\u7ef4\u5ea6\u7684\u957f\u5ea6\u662f5\uff0c\u5c06\u5176\u7406\u89e3\u4e3a<strong>\u5217<\/strong>\u7ef4\u5ea6<\/li>\n\n\n\n<li>\u5012\u6570\u7b2c\u4e8c\u4e2a\u7ef4\u5ea6\uff0c\u5373\u8fd9\u91cc\u7b2c\u4e8c\u4e2a\u7ef4\u5ea6\uff0c\u8be5\u7ef4\u5ea6\u7684\u957f\u5ea6\u662f4\uff0c\u5c06\u5176\u7406\u89e3\u4e3a<strong>\u884c<\/strong>\u7ef4\u5ea6<\/li>\n\n\n\n<li>\u5012\u6570\u7b2c\u4e09\u4e2a\u7ef4\u5ea6\uff08\u7b2c\u4e00\u4e2a\u7ef4\u5ea6\uff09\u8be5\u7ef4\u5ea6\u957f\u5ea6\u662f3\uff0c\u5c06\u5176\u7406\u89e3\u4e3a\u884c\u5217\u5f0f\u524d\u9762\u7684<strong>\u5c42<\/strong><\/li>\n<\/ul>\n\n\n\n<p>\u5faa\u7740\u8fd9\u6837\u7684\u601d\u8003\u6a21\u5f0f\uff0c\u4e0d\u65ad\u5730\u53e0\u52a0\u66f4\u591a\u7684\u201c\u5c42\u201d\uff0c\u5c31\u53ef\u4ee5\u7406\u89e3\u66f4\u9ad8\u7ef4\u5ea6\u7684\u6570\u7ec4\u4e86\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8003\u8651 2x3x4x5 \u7684\u6570\u7ec4<\/h3>\n\n\n\n<p>\u8fd9\u91cc\u5148\u8bd5\u7528\u201c\u5c42\u201d\u7684\u601d\u7ef4\uff0c\u53ef\u89c6\u5316\u7684\u8868\u793a\u8be5\u6570\u7ec4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column orczhou_0_8_font_size is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:55%\"><p>\\[<br \/>\n\\left[<br \/>\n\\begin{array}{c}<br \/>\n\\text{Layer}^{(0)}_1<br \/>\n\\left[<br \/>\n\\begin{array}{c}<br \/>\n\\text{Layer}^{(1)}_1<br \/>\n\\left[<br \/>\n\\begin{array}{c}<br \/>\n[000 &#038; 001 &#038; 002 &#038; 003 &#038; 004] \\\\<br \/>\n[005 &#038; 006 &#038; 007 &#038; 008 &#038; 009] \\\\<br \/>\n[010 &#038; 011 &#038; 012 &#038; 013 &#038; 014] \\\\<br \/>\n[015 &#038; 016 &#038; 017 &#038; 018 &#038; 019] \\\\<br \/>\n\\end{array}<br \/>\n\\right] \\\\<br \/>\n\\text{Layer}^{(1)}_2<br \/>\n\\left[<br \/>\n\\begin{array}{c}<br \/>\n[020 &#038; 021 &#038; 022 &#038; 023 &#038; 024] \\\\<br \/>\n[025 &#038; 026 &#038; 027 &#038; 028 &#038; 029] \\\\<br \/>\n[030 &#038; 031 &#038; 032 &#038; 033 &#038; 034] \\\\<br \/>\n[035 &#038; 036 &#038; 037 &#038; 038 &#038; 039] \\\\<br \/>\n\\end{array}<br \/>\n\\right] \\\\<br \/>\n\\text{Layer}^{(1)}_3<br \/>\n\\left[<br \/>\n\\begin{array}{c}<br \/>\n[040 &#038; 041 &#038; 042 &#038; 043 &#038; 044] \\\\<br \/>\n[045 &#038; 046 &#038; 047 &#038; 048 &#038; 049] \\\\<br \/>\n[050 &#038; 051 &#038; 052 &#038; 053 &#038; 054] \\\\<br \/>\n[055 &#038; 056 &#038; 057 &#038; 058 &#038; 059] \\\\<br \/>\n\\end{array}<br \/>\n\\right]<br \/>\n\\end{array}<br \/>\n\\right] \\\\<br \/>\n\\text{Layer}^{(0)}_2<br \/>\n\\left[<br \/>\n\\begin{array}{c}<br \/>\n\\text{Layer}^{(1)}_1<br \/>\n\\left[<br \/>\n\\begin{array}{c}<br \/>\n[060 &#038; 061 &#038; 062 &#038; 063 &#038; 064] \\\\<br \/>\n[065 &#038; 066 &#038; 067 &#038; 068 &#038; 069] \\\\<br \/>\n[070 &#038; 071 &#038; 072 &#038; 073 &#038; 074] \\\\<br \/>\n[075 &#038; 076 &#038; 077 &#038; 078 &#038; 079] \\\\<br \/>\n\\end{array}<br \/>\n\\right] \\\\<br \/>\n\\text{Layer}^{(1)}_2<br \/>\n\\left[<br \/>\n\\begin{array}{c}<br \/>\n[080 &#038; 081 &#038; 082 &#038; 083 &#038; 084] \\\\<br \/>\n[085 &#038; 086 &#038; 087 &#038; 088 &#038; 089] \\\\<br \/>\n[090 &#038; 091 &#038; 092 &#038; 093 &#038; 094] \\\\<br \/>\n[095 &#038; 096 &#038; 097 &#038; 098 &#038; 099] \\\\<br \/>\n\\end{array}<br \/>\n\\right] \\\\<br \/>\n\\text{Layer}^{(1)}_3<br \/>\n\\left[<br \/>\n\\begin{array}{c}<br \/>\n[100 &#038; 101 &#038; 102 &#038; 103 &#038; 104] \\\\<br \/>\n[105 &#038; 106 &#038; 107 &#038; 108 &#038; 109] \\\\<br \/>\n[110 &#038; 111 &#038; 112 &#038; 113 &#038; 114] \\\\<br \/>\n[115 &#038; 116 &#038; 117 &#038; 118 &#038; 119] \\\\<br \/>\n\\end{array}<br \/>\n\\right]<br \/>\n\\end{array}<br \/>\n\\right]<br \/>\n\\end{array}<br \/>\n\\right]<br \/>\n\\]<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column orczhou_0_6_font_size is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:45%\">\n<pre class=\"wp-block-code\"><code lang=\"python\" class=\"language-python\">&gt;&gt;&gt; np.arange(120).reshape(2,3,4,5)\narray([[[[  0,   1,   2,   3,   4],\n         [  5,   6,   7,   8,   9],\n         [ 10,  11,  12,  13,  14],\n         [ 15,  16,  17,  18,  19]],\n\n        [[ 20,  21,  22,  23,  24],\n         [ 25,  26,  27,  28,  29],\n         [ 30,  31,  32,  33,  34],\n         [ 35,  36,  37,  38,  39]],\n\n        [[ 40,  41,  42,  43,  44],\n         [ 45,  46,  47,  48,  49],\n         [ 50,  51,  52,  53,  54],\n         [ 55,  56,  57,  58,  59]]],\n\n\n       [[[ 60,  61,  62,  63,  64],\n         [ 65,  66,  67,  68,  69],\n         [ 70,  71,  72,  73,  74],\n         [ 75,  76,  77,  78,  79]],\n\n        [[ 80,  81,  82,  83,  84],\n         [ 85,  86,  87,  88,  89],\n         [ 90,  91,  92,  93,  94],\n         [ 95,  96,  97,  98,  99]],\n\n        [[100, 101, 102, 103, 104],\n         [105, 106, 107, 108, 109],\n         [110, 111, 112, 113, 114],\n         [115, 116, 117, 118, 119]]]])<\/code><\/pre>\n<\/div>\n<\/div>\n\n\n\n<p>\u7ee7\u7eed\u6309\u7167\u4e0a\u9762\u7684\u539f\u5219\uff0c\u8003\u8651\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6700\u540e\u4e00\u4e2a\u7ef4\u5ea6\uff0c\u5373\u8fd9\u91cc\u7684\u7b2c\u56db\u4e2a\u7ef4\u5ea6\uff0c\u8be5\u7ef4\u5ea6\u7684\u957f\u5ea6\u662f5\uff0c\u5c06\u5176\u7406\u89e3\u4e3a<strong>\u5217<\/strong>\u7ef4\u5ea6<\/li>\n\n\n\n<li>\u5012\u6570\u7b2c\u4e8c\u4e2a\u7ef4\u5ea6\uff0c\u5373\u8fd9\u91cc\u7b2c\u4e09\u4e2a\u7ef4\u5ea6\uff0c\u8be5\u7ef4\u5ea6\u7684\u957f\u5ea6\u662f4\uff0c\u5c06\u5176\u7406\u89e3\u4e3a<strong>\u884c<\/strong>\u7ef4\u5ea6<\/li>\n\n\n\n<li>\u5012\u6570\u7b2c\u4e09\u4e2a\u7ef4\u5ea6\uff0c\u5373\u7b2c\u4e8c\u4e2a\u7ef4\u5ea6\uff0c\u8be5\u7ef4\u5ea6\u7684\u957f\u5ea6\u662f3\uff0c\u5c06\u5176\u7406\u89e3\u4e3a\u884c\u5217\u5f0f\u524d\u9762\u7684<strong>\u5c42<\/strong><\/li>\n\n\n\n<li>\u5012\u6570\u7b2c\u56db\u4e2a\u7ef4\u5ea6\uff0c\u5373\u7b2c\u4e00\u4e2a\u7ef4\u5ea6\uff0c\u8be5\u7ef4\u5ea6\u7684\u957f\u5ea6\u662f2\uff0c\u5c06\u5176\u7406\u89e3\u4e3a\u884c\u5217\u5f0f\u524d\u9762\u7684<strong>\u5c42\u7684\u5c42<\/strong>\uff0c\u4e5f\u5c31\u662f\u4e0a\u8ff0\u7684\u201cLayer\u201d<\/li>\n<\/ul>\n\n\n\n<p>\u4f7f\u7528\u8fd9\u6837\u7684\u6a21\u5f0f\uff0c\u5c31\u53ef\u4ee5\u5c06\u4e00\u4e2a\u591a\u7ef4\u6570\u7ec4\u7684\u8868\u793a\u5e73\u9762\u5316\u3002\u5e76\u4e14\u6ce8\u610f\u5230\uff0c\u8fd9\u4e0e<code>ndarray<\/code>\u8f93\u51fa\u7684\u5f62\u5f0f\u662f\u51e0\u4e4e\u5b8c\u5168\u4e00\u81f4\u7684\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u56de\u5230\u524d\u9762\u7684\u95ee\u9898<\/h3>\n\n\n\n<p>\u6709\u4e86\u4e0a\u9762\u7684\u53ef\u89c6\u5316\u5c55\u793a\u4ee5\u53ca\u4e0a\u9762\u9010\u6b65\u7684\u4ecb\u7ecd\uff0c\u5e94\u8be5\u53ef\u4ee5\u66f4\u5bb9\u6613\u7406\u89e3\u524d\u9762<code><a href=\"https:\/\/numpy.org\/doc\/stable\/user\/absolute_beginners.html\">NumPy: the absolute basics for beginners<\/a><\/code>\u6240\u63d0\u5230\u7684\u76f4\u89c9\u201ca better mental model is to think of the column index as coming&nbsp;<em>last<\/em>&nbsp;and the row index as&nbsp;<em>second to last<\/em>\u201d\u3002<\/p>\n\n\n\n<p>\u6709\u4e86\u8fd9\u4e2a\u76f4\u89c9\uff0c\u6211\u4eec\u518d\u6765\u8003\u8651\u6700\u524d\u9762\u63d0\u5230\u7684\u95ee\u9898\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"python\" class=\"language-python\">&gt;&gt;&gt; import numpy as np\n&gt;&gt;&gt; np.array([[[1],[2]],[[3],[4]]]).shape<\/code><\/pre>\n\n\n\n<p>\u6700\u5185\u5c42\u7684\u5217\uff0c\u5c31\u662f\u6700\u540e\u7684\u7ef4\u5ea6\u957f\u5ea6\uff0c\u8fd9\u91cc\u662f 1\uff0c\u6240\u4ee5\u5c31\u662f <code>? x 1<\/code>\uff1b\u8be5\u5217\u6240\u5bf9\u5e94\u7684\u884c\u6570\uff0c\u5c31\u662f\u5012\u6570\u7b2c\u4e8c\u4e2a\u7ef4\u5ea6\u7684\u957f\u5ea6\uff0c\u8fd9\u91cc\u505a\u5982\u4e0b\u7684\u683c\u5f0f\u5316\uff0c\u53ef\u4ee5\u770b\u5230\u6709\u4e24\u884c\uff0c\u6240\u4ee5\u8fd9\u662f\u4e00\u4e2a<code>? x 2 x 1<\/code>\u7684\u6570\u7ec4\uff1b\u518d\u5411\u4e0a\u770b\u4e00\u5c42\uff0c\u5171\u6709\u4e24\u4e2a\u8be5<code>2x1<\/code>\u7684\u6570\u7ec4\uff0c\u6545\uff0c\u8be5\u6570\u7ec4\u7684<code>shape<\/code>\u65f6\uff1a<code>2x2x1<\/code>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">[\n  [\n    [1],\n    [2]\n  ],\n  [\n    [3],\n    [4]\n  ]\n]<\/code><\/pre>\n\n\n\n<p>\u518d\u786e\u8ba4\u6700\u540e\u7684\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"python\" class=\"language-python\">&gt;&gt;&gt; import numpy as np\n&gt;&gt;&gt; np.array([[[1],[2]],[[3],[4]]]).shape\n(2, 2, 1)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u6700\u540e<\/h3>\n\n\n\n<p>\u8fd9\u79cd\u7406\u89e3\u7684\u6838\u5fc3\u5373\u662f\u201ca better mental model is to think of the column index as coming&nbsp;last&nbsp;and the row index as&nbsp;second to last\u201d\uff0c\u7b80\u5355\u6982\u62ec\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u603b\u662f\u5c06\u6700\u540e\u4e00\u4e2a\u7ef4\u5ea6\u7406\u89e3\u4e3a\u5217\u7ef4\u5ea6<\/li>\n\n\n\n<li>\u603b\u662f\u5c06\u5012\u6570\u7b2c\u4e8c\u4e2a\u7ef4\u5ea6\u7406\u89e3\u4e3a\u884c\u7ef4\u5ea6<\/li>\n\n\n\n<li>\u5269\u4f59\u7684\u7ef4\u5ea6\uff0c\u5219\u662f\u901a\u8fc7\u5c42\u7684\u65b9\u5f0f\u53bb\u6784\u5efa<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u673a\u5668\u5b66\u4e60\u4e2d\u5927\u91cf\u7684\u4f7f\u7528NumPy\u4f5c\u4e3a\u5176\u57fa\u7840\u7684\u6570\u636e\u7ed3\u6784\uff0cndarray\u662fNumPy\u7684\u6838\u5fc3\u6570\u636e\u5bf9\u8c61\u3002\u5bf9\u4e8endarray\u9ad8\u7ef4\u6570\u7ec4\u7684\u4e00\u4e2a\u975e\u5e38\u5bb9\u6613\u4ea7\u751f\u7684\u8bef\u89e3\u662f\uff0c\u4f7f\u7528\u6570\u5b66\u4e2d\u7684\u77e9\u9635\uff08\u6216\u8005\u53eb\u201c\u884c\u5217\u5f0f\u201d\uff09\u6982\u5ff5\u53bb\u5c1d\u8bd5\u7406\u89e3\u66f4\u9ad8\u7ef4\u7684\u573a\u666f\uff0c\u6216\u8005\u4f7f\u7528\u66f4\u9ad8\u7ef4\u7a7a\u95f4\u53bb\u7406\u89e3\uff0c\u8fd9\u6837\u90fd\u4f1a\u5bfc\u81f4\u96be\u4ee5\u8f83\u597d\u7684\u7406\u89e3\u66f4\u9ad8\u7ef4\uff085\u62166\u7ef4\uff09\u7684\u6570\u7ec4\u3002\u672c\u6587\u4f7f\u7528\u8f83\u4e3a\u76f4\u89c2\u7684\u793a\u4f8b\u548c\u53ef\u89c6\u5316\u7684\u5c55\u793a\uff0c\u66f4\u4e3a\u201c\u6807\u51c6\u201d\uff08\u6587\u6863\u63a8\u8350\u7684\uff09\u7684\u65b9\u5f0f\u53bb\u7406\u89e3ndarray\u7684\u66f4\u9ad8\u7ef4\u6570\u7ec4\u3002\u66f4\u591a\u8be6\u7ec6\u5185\u5bb9\uff0c\u53ef\u4ee5\u53c2\u8003\u9605\u8bfb\uff1a \u95ee\u9898 \u5728\u673a\u5668\u5b66\u4e60\u4e2d\uff0c\u7ecf\u5e38\u8981\u5bf9\u591a\u7ef4\u7684\u6570\u7ec4\u505a\u5404\u79cd\u64cd\u4f5c\u3002\u5bf9\u9ad8\u7ef4\u6570\u7ec4\u5efa\u7acb\u66f4\u597d\u7684\u76f4\u89c9\u7406\u89e3\uff0c\u5219\u6709\u5229\u4e8e\u53bb\u7406\u89e3\u8fd9\u4e9b\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u8003\u8651\u53f3\u4fa7\u7684\u4ee3\u7801\uff0c\u60f3\u4e00\u60f3\u8be5\u4ee3\u7801\u7684\u8f93\u51fa\u662f\u4ec0\u4e48\uff1f \u8981\u56de\u7b54\u8fd9\u4e2a\u95ee\u9898\uff0c\u5219\u9700\u8981\u5efa\u7acb\u5bf9\u4e8e\u591a\u7ef4\u6570\u7ec4\u7ed3\u6784\u7684\u7406\u89e3\u3002 \u6587\u6863\u4e2d\u5bf9\u4e8e\u9ad8\u7ef4\u6570\u7ec4\u7406\u89e3\u7684\u5efa\u8bae \u5728NumPy: the absolute basics for beginners\u4e2d\u6709\u5982\u4e0b\u4e00\u6bb5\u8bdd\uff1a It is familiar practice in mathematics to refer to elements of a matrix by the row index first and the column index second. This happens to be true for two-dimensional arrays, but a better mental model is to think of the column index as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":18112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"wp-custom-template-a-1440-px-width-template","format":"standard","meta":{"_eb_attr":"","inline_featured_image":false,"_tocer_settings":[],"footnotes":""},"categories":[137],"tags":[],"class_list":["post-18023","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learning-more"],"_links":{"self":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/18023","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/comments?post=18023"}],"version-history":[{"count":19,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/18023\/revisions"}],"predecessor-version":[{"id":18181,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/18023\/revisions\/18181"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/media\/18112"}],"wp:attachment":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/media?parent=18023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/categories?post=18023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/tags?post=18023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}