{"id":549,"date":"2022-07-05T17:06:45","date_gmt":"2023-10-13T03:05:42","guid":{"rendered":"https:\/\/www.silicloud.com\/ja\/blog\/index.php\/2023\/11\/30\/python%e3%81%aenumpy-append\/"},"modified":"2025-08-01T00:30:11","modified_gmt":"2025-07-31T15:30:11","slug":"python%e3%81%aenumpy-append","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/ja\/blog\/python%e3%81%aenumpy-append\/","title":{"rendered":"Python\u306enumpy.append()"},"content":{"rendered":"<p>Python\u306enumpy\u306eappend()\u95a2\u6570\u306f\u30012\u3064\u306e\u914d\u5217\u3092\u7d50\u5408\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002\u3053\u306e\u95a2\u6570\u306f\u65b0\u3057\u3044\u914d\u5217\u3092\u8fd4\u3057\u3001\u5143\u306e\u914d\u5217\u306f\u5909\u66f4\u3055\u308c\u307e\u305b\u3093\u3002<\/p>\n<h2>NumPy\u306eappend()\u306e\u69cb\u6587<\/h2>\n<p>\u95a2\u6570\u306e\u69cb\u6587\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>numpy.append(arr, values, axis=None)\r\n<\/code><\/pre>\n<ul class=\"post-ul\">\n<li>The arr can be an array-like object or a NumPy array. The values are appended to a copy of this array.<\/li>\n<li>The values are array-like objects and it\u2019s appended to the end of the \u201carr\u201d elements.<\/li>\n<li>The axis specifies the axis along which values are appended. If the axis is not provided, both the arrays are flattened.<\/li>\n<\/ul>\n<h2>Python\u306enumpy.append()\u306e\u4f8b<\/h2>\n<p>NumPy\u306eappend()\u95a2\u6570\u306e\u3044\u304f\u3064\u304b\u306e\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>1. 2\u3064\u306e\u914d\u5217\u3092\u5e73\u5766\u5316\u3059\u308b<\/h3>\n<pre class=\"post-pre\"><code>import numpy as np\r\n\r\narr1 = np.array([[1, 2], [3, 4]])\r\narr2 = np.array([[10, 20], [30, 40]])\r\n\r\n# no axis provided, array elements will be flattened\r\narr_flat = np.append(arr1, arr2)\r\n\r\nprint(arr_flat)  # [ 1  2  3  4 10 20 30 40]\r\n<\/code><\/pre>\n<h3>2. \u8ef8\u306b\u6cbf\u3063\u3066\u7d71\u5408<\/h3>\n<pre class=\"post-pre\"><code>import numpy as np\r\n\r\narr_merged = np.append([[1, 2], [3, 4]], [[10, 20], [30, 40]], axis=0)\r\nprint(f'Merged 2x2 Arrays along Axis-0:\\n{arr_merged}')\r\n\r\narr_merged = np.append([[1, 2], [3, 4]], [[10, 20], [30, 40]], axis=1)\r\nprint(f'Merged 2x2 Arrays along Axis-1:\\n{arr_merged}')\r\n<\/code><\/pre>\n<p>\u51fa\u529b\uff1a<\/p>\n<pre class=\"post-pre\"><code>Merged 2x2 Arrays along Axis-0:\r\n[[ 1  2]\r\n [ 3  4]\r\n [10 20]\r\n [30 40]]\r\nMerged 2x2 Arrays along Axis-1:\r\n[[ 1  2 10 20]\r\n [ 3  4 30 40]]\r\n<\/code><\/pre>\n<ul class=\"post-ul\">\n<li>When the 2&#215;2 arrays are merged along the x-axis, the output array size is 4&#215;2.<\/li>\n<li>When the 2&#215;2 arrays are merged along the y-axis, the output array size is 2&#215;4.<\/li>\n<\/ul>\n<h3>3. \u7570\u306a\u308b\u5f62\u72b6\u306e\u914d\u5217\u306e\u7d50\u5408<\/h3>\n<p>append()\u95a2\u6570\u306f\u3001\u8ef8\u3092\u9664\u3044\u305f\u5834\u5408\u306b\u4e21\u65b9\u306e\u914d\u5217\u306e\u5f62\u72b6\u304c\u7570\u306a\u308b\u5834\u5408\u306bValueError\u3092\u9001\u51fa\u3057\u307e\u3059\u3002\u5358\u7d14\u306a\u4f8b\u3092\u4f7f\u3063\u3066\u3053\u306e\u30b7\u30ca\u30ea\u30aa\u3092\u7406\u89e3\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"post-pre\"><code>arr3 = np.append([[1, 2]], [[1, 2, 3], [1, 2, 3]])\r\nprint(arr3)\r\n\r\narr3 = np.append([[1, 2]], [[1, 2], [3, 4]], axis=0)\r\nprint(arr3)\r\n<\/code><\/pre>\n<ul class=\"post-ul\">\n<li>In the first example, the array elements are flattened. So even if they have completely different size &#8211; 1&#215;2 and 2&#215;3, the append() works fine.<\/li>\n<li>In the second example, the array shapes are 1&#215;2 and 2&#215;2. Since we are appending along the 0-axis, the 0-axis shape can be different. The other shapes should be the same, so this append() will also work fine.<\/li>\n<\/ul>\n<p>\u7d50\u679c\uff1a<\/p>\n<pre class=\"post-pre\"><code>[1 2 1 2 3 1 2 3]\r\n\r\n[[1 2]\r\n [1 2]\r\n [3 4]]\r\n<\/code><\/pre>\n<p>\u5225\u306e\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002ValueError\u304c\u767a\u751f\u3059\u308b\u5834\u5408\u3092\u8003\u3048\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"post-pre\"><code>&gt;&gt;&gt; import numpy as np\r\n&gt;&gt;&gt; \r\n&gt;&gt;&gt; arr3 = np.append([[1, 2]], [[1, 2, 3]], axis=0)\r\nTraceback (most recent call last):\r\n  File \"\", line 1, in \r\n  File \"\/Library\/Frameworks\/Python.framework\/Versions\/3.7\/lib\/python3.7\/site-packages\/numpy\/lib\/function_base.py\", line 4528, in append\r\n    return concatenate((arr, values), axis=axis)\r\nValueError: all the input array dimensions except for the concatenation axis must match exactly\r\n&gt;&gt;&gt; \r\n<\/code><\/pre>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/6564944edaa94e2bdf7bf098\/22-0.png\" alt=\"Numpy Append Valueerror\" \/><\/div>\n<p>\u914d\u5217\u306e\u5f62\u72b6\u306f1&#215;2\u30682&#215;3\u3067\u3059\u3002axis-1\u306e\u5f62\u72b6\u304c\u7570\u306a\u308b\u305f\u3081\u3001ValueError\u304c\u767a\u751f\u3057\u307e\u3059\u3002\u53c2\u7167\uff1aAPI\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\u306enumpy\u306eappend()\u95a2\u6570\u306f\u30012\u3064\u306e\u914d\u5217\u3092\u7d50\u5408\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002\u3053\u306e\u95a2\u6570\u306f\u65b0\u3057\u3044\u914d\u5217\u3092\u8fd4\u3057\u3001\u5143\u306e\u914d\u5217\u306f\u5909\u66f4\u3055\u308c\u307e\u305b\u3093\u3002 NumPy\u306eappend()\u306e\u69cb\u6587 \u95a2\u6570\u306e\u69cb\u6587\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002 nu [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[31,26],"class_list":["post-549","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-python","tag-26"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python\u306enumpy.append() - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Python\u306enumpy.append()\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/ja\/blog\/python\u306enumpy-append\/\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python\u306enumpy.append()\" \/>\n<meta property=\"og:description\" content=\"Python\u306enumpy.append()\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/ja\/blog\/python\u306enumpy-append\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-13T03:05:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-31T15:30:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/6564944edaa94e2bdf7bf098\/22-0.png\" \/>\n<meta name=\"author\" content=\"\u5149, \u660e\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u57f7\u7b46\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u5149, \u660e\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"6\u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/python%e3%81%aenumpy-append\/\",\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/python%e3%81%aenumpy-append\/\",\"name\":\"Python\u306enumpy.append() - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#website\"},\"datePublished\":\"2023-10-13T03:05:42+00:00\",\"dateModified\":\"2025-07-31T15:30:11+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/9ee62cea876d247deba14a0ac7ba5b55\"},\"description\":\"Python\u306enumpy.append()\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/python%e3%81%aenumpy-append\/#breadcrumb\"},\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/ja\/blog\/python%e3%81%aenumpy-append\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/python%e3%81%aenumpy-append\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/ja\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\u306enumpy.append()\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"ja\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/9ee62cea876d247deba14a0ac7ba5b55\",\"name\":\"\u5149, \u660e\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/3dffb6c754b95e3fbdcd8973f4375ff9dd10d41e4f6632ad08d4d59ccc35af8d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/3dffb6c754b95e3fbdcd8973f4375ff9dd10d41e4f6632ad08d4d59ccc35af8d?s=96&d=mm&r=g\",\"caption\":\"\u5149, \u660e\"},\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/author\/hikariakira\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/python%e3%81%aenumpy-append\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python\u306enumpy.append() - Blog - Silicon Cloud","description":"Python\u306enumpy.append()\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/ja\/blog\/python\u306enumpy-append\/","og_locale":"ja_JP","og_type":"article","og_title":"Python\u306enumpy.append()","og_description":"Python\u306enumpy.append()\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","og_url":"https:\/\/www.silicloud.com\/ja\/blog\/python\u306enumpy-append\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-10-13T03:05:42+00:00","article_modified_time":"2025-07-31T15:30:11+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/6564944edaa94e2bdf7bf098\/22-0.png"}],"author":"\u5149, \u660e","twitter_card":"summary_large_image","twitter_misc":{"\u57f7\u7b46\u8005":"\u5149, \u660e","\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593":"6\u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/ja\/blog\/python%e3%81%aenumpy-append\/","url":"https:\/\/www.silicloud.com\/ja\/blog\/python%e3%81%aenumpy-append\/","name":"Python\u306enumpy.append() - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/#website"},"datePublished":"2023-10-13T03:05:42+00:00","dateModified":"2025-07-31T15:30:11+00:00","author":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/9ee62cea876d247deba14a0ac7ba5b55"},"description":"Python\u306enumpy.append()\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/python%e3%81%aenumpy-append\/#breadcrumb"},"inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/ja\/blog\/python%e3%81%aenumpy-append\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/ja\/blog\/python%e3%81%aenumpy-append\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/ja\/blog\/"},{"@type":"ListItem","position":2,"name":"Python\u306enumpy.append()"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#website","url":"https:\/\/www.silicloud.com\/ja\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"ja"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/9ee62cea876d247deba14a0ac7ba5b55","name":"\u5149, \u660e","image":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/3dffb6c754b95e3fbdcd8973f4375ff9dd10d41e4f6632ad08d4d59ccc35af8d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3dffb6c754b95e3fbdcd8973f4375ff9dd10d41e4f6632ad08d4d59ccc35af8d?s=96&d=mm&r=g","caption":"\u5149, \u660e"},"url":"https:\/\/www.silicloud.com\/ja\/blog\/author\/hikariakira\/"},{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.silicloud.com\/ja\/blog\/python%e3%81%aenumpy-append\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/549","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/comments?post=549"}],"version-history":[{"count":1,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/549\/revisions"}],"predecessor-version":[{"id":42030,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/549\/revisions\/42030"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/media?parent=549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/categories?post=549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/tags?post=549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}