{"id":2336,"date":"2023-07-22T17:32:44","date_gmt":"2023-07-22T17:32:44","guid":{"rendered":"https:\/\/statorials.org\/it\/numpy-aggiunge-una-riga-alla-matrice\/"},"modified":"2023-07-22T17:32:44","modified_gmt":"2023-07-22T17:32:44","slug":"numpy-aggiunge-una-riga-alla-matrice","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/numpy-aggiunge-una-riga-alla-matrice\/","title":{"rendered":"Come aggiungere una riga a una matrice in numpy (con esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare la seguente sintassi per aggiungere una riga a una matrice in NumPy:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#add new_row to current_matrix<\/span>\ncurrent_matrix = np. <span style=\"color: #3366ff;\">vstack<\/span> ([current_matrix, new_row])\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Puoi anche utilizzare la seguente sintassi per aggiungere solo righe a una matrice che soddisfa una determinata condizione:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#only add rows where first element is less than 10<\/span>\ncurrent_matrix = np. <span style=\"color: #3366ff;\">vstack<\/span> ((current_matrix, new_rows[new_rows[:,0] &lt; <span style=\"color: #008000;\">10<\/span> ]))<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Gli esempi seguenti mostrano come utilizzare questa sintassi nella pratica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: aggiungi una riga alla matrice in NumPy<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come aggiungere una nuova riga a una matrice in NumPy:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n\n<span style=\"color: #008080;\">#define matrix\n<\/span>current_matrix = np. <span style=\"color: #3366ff;\">array<\/span> ([[1,2,3], [4, 5, 6], [7, 8, 9]])\n\n<span style=\"color: #008080;\">#define row to add\n<\/span>new_row = np. <span style=\"color: #3366ff;\">array<\/span> ([10, 11, 12])\n\n<span style=\"color: #008080;\">#add new row to matrix\n<\/span>current_matrix = np. <span style=\"color: #3366ff;\">vstack<\/span> ([current_matrix, new_row])\n\n<span style=\"color: #008080;\">#view updated matrix\n<\/span>current_matrix\n\narray([[ 1, 2, 3],\n       [4,5,6],\n       [7, 8, 9],\n       [10, 11, 12]])\n<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che l&#8217;ultima riga \u00e8 stata aggiunta con successo alla matrice.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: aggiungere righe alla matrice in base alla condizione<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">Il codice seguente mostra come aggiungere pi\u00f9 nuove righe a una matrice esistente in base a una condizione specifica:<\/span><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n\n<span style=\"color: #008080;\">#define matrix\n<\/span>current_matrix = np. <span style=\"color: #3366ff;\">array<\/span> ([[1, 2, 3], [4, 5, 6], [7, 8, 9]])\n\n<span style=\"color: #008080;\">#define potential new rows to add\n<\/span>new_rows = np. <span style=\"color: #3366ff;\">array<\/span> ([[6, 8, 10], [8, 10, 12], [10, 12, 14]])\n\n<span style=\"color: #008080;\">#only add rows where first element in row is less than 10\n<\/span>current_matrix = np. <span style=\"color: #3366ff;\">vstack<\/span> ((current_matrix, new_rows[new_rows[:,0] &lt; <span style=\"color: #008000;\">10<\/span> ]))\n\n<span style=\"color: #008080;\">#view updated matrix\n<\/span>current_matrix\n\narray([[ 1, 2, 3],\n       [4,5,6],\n       [7, 8, 9],\n       [6, 8, 10],\n       [8, 10, 12]])\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Sono state aggiunte solo le righe il cui primo elemento era inferiore a 10.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : puoi trovare la documentazione online completa per la funzione <strong>vstack()<\/strong> <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.vstack.html\" target=\"_blank\" rel=\"noopener\">qui<\/a> .<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">I seguenti tutorial spiegano come eseguire altre operazioni comuni in NumPy:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/indice-del-valore-di-ricerca-numpy\/\" target=\"_blank\" rel=\"noopener\">Come trovare l&#8217;indice dei valori nell&#8217;array NumPy<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/aggiungi-larray-numpy-al-dataframe-panda\/\" target=\"_blank\" rel=\"noopener\">Come aggiungere un array Numpy a Pandas DataFrame<\/a><br \/><a href=\"https:\/\/statorials.org\/it\/array-numpy-per-dataframe-panda\/\" target=\"_blank\" rel=\"noopener\">Come convertire un array NumPy in Pandas DataFrame<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare la seguente sintassi per aggiungere una riga a una matrice in NumPy: #add new_row to current_matrix current_matrix = np. vstack ([current_matrix, new_row]) Puoi anche utilizzare la seguente sintassi per aggiungere solo righe a una matrice che soddisfa una determinata condizione: #only add rows where first element is less than 10 current_matrix = [&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":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Come aggiungere una riga a una matrice in NumPy (con esempi) - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come aggiungere una riga a una matrice in NumPy, con diversi esempi.\" \/>\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\/it\/numpy-aggiunge-una-riga-alla-matrice\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come aggiungere una riga a una matrice in NumPy (con esempi) - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come aggiungere una riga a una matrice in NumPy, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/numpy-aggiunge-una-riga-alla-matrice\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-22T17:32:44+00:00\" \/>\n<meta name=\"author\" content=\"Benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minuto\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/numpy-aggiunge-una-riga-alla-matrice\/\",\"url\":\"https:\/\/statorials.org\/it\/numpy-aggiunge-una-riga-alla-matrice\/\",\"name\":\"Come aggiungere una riga a una matrice in NumPy (con esempi) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-22T17:32:44+00:00\",\"dateModified\":\"2023-07-22T17:32:44+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come aggiungere una riga a una matrice in NumPy, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/numpy-aggiunge-una-riga-alla-matrice\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/numpy-aggiunge-una-riga-alla-matrice\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/numpy-aggiunge-una-riga-alla-matrice\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come aggiungere una riga a una matrice in numpy (con esempi)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/it\/#website\",\"url\":\"https:\/\/statorials.org\/it\/\",\"name\":\"Statorials\",\"description\":\"La tua guida all&#039;alfabetizzazione statistica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/it\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\",\"name\":\"Benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin anderson\"},\"description\":\"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9\",\"sameAs\":[\"https:\/\/statorials.org\/it\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Come aggiungere una riga a una matrice in NumPy (con esempi) - Statorials","description":"Questo tutorial spiega come aggiungere una riga a una matrice in NumPy, con diversi esempi.","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\/it\/numpy-aggiunge-una-riga-alla-matrice\/","og_locale":"it_IT","og_type":"article","og_title":"Come aggiungere una riga a una matrice in NumPy (con esempi) - Statorials","og_description":"Questo tutorial spiega come aggiungere una riga a una matrice in NumPy, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/numpy-aggiunge-una-riga-alla-matrice\/","og_site_name":"Statorials","article_published_time":"2023-07-22T17:32:44+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"1 minuto"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/numpy-aggiunge-una-riga-alla-matrice\/","url":"https:\/\/statorials.org\/it\/numpy-aggiunge-una-riga-alla-matrice\/","name":"Come aggiungere una riga a una matrice in NumPy (con esempi) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-22T17:32:44+00:00","dateModified":"2023-07-22T17:32:44+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come aggiungere una riga a una matrice in NumPy, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/numpy-aggiunge-una-riga-alla-matrice\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/numpy-aggiunge-una-riga-alla-matrice\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/numpy-aggiunge-una-riga-alla-matrice\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come aggiungere una riga a una matrice in numpy (con esempi)"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/it\/#website","url":"https:\/\/statorials.org\/it\/","name":"Statorials","description":"La tua guida all&#039;alfabetizzazione statistica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/it\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae","name":"Benjamin anderson","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Benjamin anderson"},"description":"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9","sameAs":["https:\/\/statorials.org\/it"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2336"}],"collection":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/comments?post=2336"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2336\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=2336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=2336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=2336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}