{"id":2187,"date":"2023-07-23T08:26:42","date_gmt":"2023-07-23T08:26:42","guid":{"rendered":"https:\/\/statorials.org\/nl\/numpy-alle-invoerarrays-moeten-hetzelfde-aantal-dimensies-hebben\/"},"modified":"2023-07-23T08:26:42","modified_gmt":"2023-07-23T08:26:42","slug":"numpy-alle-invoerarrays-moeten-hetzelfde-aantal-dimensies-hebben","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/numpy-alle-invoerarrays-moeten-hetzelfde-aantal-dimensies-hebben\/","title":{"rendered":"Oplossing: alle invoerarrays moeten hetzelfde aantal dimensies hebben"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Een fout die u kunt tegenkomen bij het gebruik van NumPy is:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #ff0000;\">ValueError<\/span> <span style=\"color: #000000;\">: all the input arrays must have same number of dimensions<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Deze fout treedt op wanneer u twee NumPy-arrays met verschillende afmetingen probeert samen te voegen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Het volgende voorbeeld laat zien hoe u deze fout in de praktijk kunt corrigeren.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Hoe de fout te reproduceren<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Stel dat we de volgende twee NumPy-arrays hebben:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n\n<span style=\"color: #008080;\">#create first array\n<span style=\"color: #000000;\">array1 = np. <span style=\"color: #3366ff;\">array<\/span> ([[1, 2], [3, 4], [5,6], [7,8]])\n\n<span style=\"color: #008000;\">print<\/span> (array1) \n\n[[1 2]\n [3 4]\n [5 6]\n [7 8]]\n\n<span style=\"color: #008080;\">#create second array \n<\/span>array2 = np. <span style=\"color: #3366ff;\">array<\/span> ([9,10,11,12])\n\n<span style=\"color: #008000;\">print<\/span> (array2)\n\n[9 10 11 12]<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Stel nu dat we de functie <strong>concatenate()<\/strong> proberen te gebruiken om de twee arrays in \u00e9\u00e9n array te combineren:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#attempt to concatenate the two arrays\n<span style=\"color: #000000;\">n.p. <span style=\"color: #3366ff;\">concatenate<\/span> ([array1, array2])\n\n<span style=\"color: #ff0000;\">ValueError <span style=\"color: #000000;\">: all the input arrays must have same number of dimensions, but the array at<\/span>\n<span style=\"color: #000000;\">index 0 has 2 dimension(s) and the array at index 1 has 1 dimension(s)\n<\/span><\/span><\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">We ontvangen een <strong>ValueError<\/strong> omdat de twee arrays verschillende afmetingen hebben.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Hoe u de fout kunt oplossen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">We kunnen twee methoden gebruiken om deze fout op te lossen.<\/span><\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Methode 1: Gebruik np.column_stack<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">E\u00e9n manier om de twee tabellen samen te voegen en fouten te voorkomen, is door de functie <strong>column_stack()<\/strong> als volgt te gebruiken:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\">n.p. <span style=\"color: #3366ff;\">column_stack<\/span> ((array1, array2))\n\narray([[ 1, 2, 9],\n       [3, 4, 10],\n       [5, 6, 11],\n       [7, 8, 12]])\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Merk op dat we de twee arrays met succes zonder fouten kunnen samenvoegen.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Methode 2: Gebruik np.c_<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">We kunnen de twee tabellen ook aaneenschakelen en tegelijkertijd fouten vermijden met de functie <strong>np.c_<\/strong> als volgt:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\">n.p. <span style=\"color: #3366ff;\">c_<\/span> [array1, array2]\n\narray([[ 1, 2, 9],\n       [3, 4, 10],\n       [5, 6, 11],\n       [7, 8, 12]])\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Merk op dat deze functie exact hetzelfde resultaat retourneert als de vorige methode.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">In de volgende tutorials wordt uitgelegd hoe u andere veelvoorkomende fouten in Python kunt oplossen:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/pandas-sleutelfout\/\" target=\"_blank\" rel=\"noopener\">Hoe KeyError in Panda&#8217;s te repareren<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/valueerror-kan-float-nan-niet-omzetten-in-geheel-getal\/\" target=\"_blank\" rel=\"noopener\">Oplossing: ValueError: Kan float NaN niet naar int converteren<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/de-operanden-konden-niet-met-de-formulieren-worden-uitgezonden\/\" target=\"_blank\" rel=\"noopener\">Oplossing: ValueError: Operanden konden niet worden uitgezonden met vormen<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Een fout die u kunt tegenkomen bij het gebruik van NumPy is: ValueError : all the input arrays must have same number of dimensions Deze fout treedt op wanneer u twee NumPy-arrays met verschillende afmetingen probeert samen te voegen. Het volgende voorbeeld laat zien hoe u deze fout in de praktijk kunt corrigeren. Hoe de [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-2187","post","type-post","status-publish","format-standard","hentry","category-gids"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Oplossing: alle invoerarrays moeten hetzelfde aantal dimensies hebben - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u de volgende fout in NumPy kunt oplossen: ValueError: Alle invoerarrays moeten hetzelfde aantal dimensies hebben.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/nl\/numpy-alle-invoerarrays-moeten-hetzelfde-aantal-dimensies-hebben\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Oplossing: alle invoerarrays moeten hetzelfde aantal dimensies hebben - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u de volgende fout in NumPy kunt oplossen: ValueError: Alle invoerarrays moeten hetzelfde aantal dimensies hebben.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/numpy-alle-invoerarrays-moeten-hetzelfde-aantal-dimensies-hebben\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-23T08:26:42+00:00\" \/>\n<meta name=\"author\" content=\"Dr.benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr.benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"2\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/numpy-alle-invoerarrays-moeten-hetzelfde-aantal-dimensies-hebben\/\",\"url\":\"https:\/\/statorials.org\/nl\/numpy-alle-invoerarrays-moeten-hetzelfde-aantal-dimensies-hebben\/\",\"name\":\"Oplossing: alle invoerarrays moeten hetzelfde aantal dimensies hebben - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-23T08:26:42+00:00\",\"dateModified\":\"2023-07-23T08:26:42+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u de volgende fout in NumPy kunt oplossen: ValueError: Alle invoerarrays moeten hetzelfde aantal dimensies hebben.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/numpy-alle-invoerarrays-moeten-hetzelfde-aantal-dimensies-hebben\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/numpy-alle-invoerarrays-moeten-hetzelfde-aantal-dimensies-hebben\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/numpy-alle-invoerarrays-moeten-hetzelfde-aantal-dimensies-hebben\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Oplossing: alle invoerarrays moeten hetzelfde aantal dimensies hebben\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/nl\/#website\",\"url\":\"https:\/\/statorials.org\/nl\/\",\"name\":\"Statorials\",\"description\":\"Uw gids voor statistische competentie\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/nl\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\",\"name\":\"Dr.benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr.benjamin anderson\"},\"description\":\"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder\",\"sameAs\":[\"http:\/\/statorials.org\/nl\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Oplossing: alle invoerarrays moeten hetzelfde aantal dimensies hebben - Statorials","description":"In deze tutorial wordt uitgelegd hoe u de volgende fout in NumPy kunt oplossen: ValueError: Alle invoerarrays moeten hetzelfde aantal dimensies hebben.","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:\/\/statorials.org\/nl\/numpy-alle-invoerarrays-moeten-hetzelfde-aantal-dimensies-hebben\/","og_locale":"de_DE","og_type":"article","og_title":"Oplossing: alle invoerarrays moeten hetzelfde aantal dimensies hebben - Statorials","og_description":"In deze tutorial wordt uitgelegd hoe u de volgende fout in NumPy kunt oplossen: ValueError: Alle invoerarrays moeten hetzelfde aantal dimensies hebben.","og_url":"https:\/\/statorials.org\/nl\/numpy-alle-invoerarrays-moeten-hetzelfde-aantal-dimensies-hebben\/","og_site_name":"Statorials","article_published_time":"2023-07-23T08:26:42+00:00","author":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr.benjamin anderson","Gesch\u00e4tzte Lesezeit":"2\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/nl\/numpy-alle-invoerarrays-moeten-hetzelfde-aantal-dimensies-hebben\/","url":"https:\/\/statorials.org\/nl\/numpy-alle-invoerarrays-moeten-hetzelfde-aantal-dimensies-hebben\/","name":"Oplossing: alle invoerarrays moeten hetzelfde aantal dimensies hebben - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-23T08:26:42+00:00","dateModified":"2023-07-23T08:26:42+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u de volgende fout in NumPy kunt oplossen: ValueError: Alle invoerarrays moeten hetzelfde aantal dimensies hebben.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/numpy-alle-invoerarrays-moeten-hetzelfde-aantal-dimensies-hebben\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/numpy-alle-invoerarrays-moeten-hetzelfde-aantal-dimensies-hebben\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/numpy-alle-invoerarrays-moeten-hetzelfde-aantal-dimensies-hebben\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Oplossing: alle invoerarrays moeten hetzelfde aantal dimensies hebben"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/nl\/#website","url":"https:\/\/statorials.org\/nl\/","name":"Statorials","description":"Uw gids voor statistische competentie","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/nl\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de"},{"@type":"Person","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219","name":"Dr.benjamin anderson","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/","url":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr.benjamin anderson"},"description":"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder","sameAs":["http:\/\/statorials.org\/nl"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/2187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/comments?post=2187"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/2187\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=2187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=2187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=2187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}