{"id":3317,"date":"2023-07-18T03:15:52","date_gmt":"2023-07-18T03:15:52","guid":{"rendered":"https:\/\/statorials.org\/it\/sostituire-intorpidito\/"},"modified":"2023-07-18T03:15:52","modified_gmt":"2023-07-18T03:15:52","slug":"sostituire-intorpidito","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/sostituire-intorpidito\/","title":{"rendered":"Come sostituire gli elementi in un array numpy (3 esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare i seguenti metodi per sostituire gli elementi in un array NumPy:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: sostituire gli elementi pari a un determinato valore<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#replace all elements equal to 8 with a new value of 20\n<\/span>my_array[my_array == <span style=\"color: #008000;\">8<\/span> ] = <span style=\"color: #008000;\">20\n<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: sostituisci gli elementi in base a una condizione<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#replace all elements greater than 8 with a new value of 20\n<\/span>my_array[my_array &gt; <span style=\"color: #008000;\">8<\/span> ] = <span style=\"color: #008000;\">20<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 3: sostituzione di elementi in base a pi\u00f9 condizioni<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#replace all elements greater than 8 or less than 6 with a new value of 20\n<\/span>my_array[(my_array &gt; <span style=\"color: #008000;\">8<\/span> ) | (my_array &lt; <span style=\"color: #008000;\">6<\/span> )] = <span style=\"color: #008000;\">20<\/span>\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">I seguenti esempi mostrano come utilizzare ciascun metodo nella pratica con il seguente array NumPy:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><span style=\"color: #008080;\"><b><span style=\"color: #000000;\"><span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n\n<span style=\"color: #008080;\">#create array\n<\/span>my_array = np. <span style=\"color: #3366ff;\">array<\/span> ([4, 5, 5, 7, 8, 8, 9, 12])\n\n<span style=\"color: #008080;\">#view array\n<\/span><span style=\"color: #008000;\">print<\/span> (my_array)\n\n[4 5 5 7 8 8 9 12]\n<\/span><\/b><\/span><\/span><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Metodo 1: sostituire gli elementi pari a un determinato valore<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come sostituire tutti gli elementi dell&#8217;array NumPy pari a <strong>8<\/strong> con un nuovo valore pari a <strong>20<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#replace all elements equal to 8 with 20\n<\/span>my_array[my_array == <span style=\"color: #008000;\">8<\/span> ] = <span style=\"color: #008000;\">20<\/span>\n\n<span style=\"color: #008080;\">#view updated array\n<\/span><span style=\"color: #008000;\">print<\/span> (my_array)\n\n[4 5 5 7 20 20 9 12]\n<\/strong><\/span><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Metodo 2: sostituisci gli elementi in base a una condizione<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come sostituire tutti gli elementi nell&#8217;array NumPy maggiori di <strong>8<\/strong> con un nuovo valore pari a <strong>20<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#replace all elements greater than 8 with 20\n<\/span>my_array[my_array &gt; <span style=\"color: #008000;\">8<\/span> ] = <span style=\"color: #008000;\">20<\/span>\n\n<span style=\"color: #008080;\">#view updated array\n<\/span><span style=\"color: #008000;\">print<\/span> (my_array)\n\n[4 5 5 7 8 8 20 20]\n<\/strong><\/span><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Metodo 3: sostituzione di elementi in base a pi\u00f9 condizioni<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come sostituire tutti gli elementi nell&#8217;array NumPy maggiori di <strong>8<\/strong> o minori di <strong>6<\/strong> con un nuovo valore di <strong>20<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#replace all elements greater than 8 or less than 6 with a new value of 20\n<\/span>my_array[(my_array &gt; <span style=\"color: #008000;\">8<\/span> ) | (my_array &lt; <span style=\"color: #008000;\">6<\/span> )] = <span style=\"color: #008000;\">20<\/span>\n\n<span style=\"color: #008080;\">#view updated array\n<\/span><span style=\"color: #008000;\">print<\/span> (my_array)\n\n[20 20 20 7 8 8 20 20]\n<\/strong><\/span><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h2>\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\/modalita-digitale\/\" target=\"_blank\" rel=\"noopener\">Come calcolare la modalit\u00e0 dell&#8217;array NumPy<\/a><br \/> <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\/carta-digitale\/\" target=\"_blank\" rel=\"noopener\">Come mappare una funzione su un array NumPy<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare i seguenti metodi per sostituire gli elementi in un array NumPy: Metodo 1: sostituire gli elementi pari a un determinato valore #replace all elements equal to 8 with a new value of 20 my_array[my_array == 8 ] = 20 Metodo 2: sostituisci gli elementi in base a una condizione #replace all elements [&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 sostituire gli elementi in un array NumPy (3 esempi) - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come sostituire gli elementi in un array 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\/sostituire-intorpidito\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come sostituire gli elementi in un array NumPy (3 esempi) - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come sostituire gli elementi in un array NumPy, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/sostituire-intorpidito\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-18T03:15:52+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=\"2 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/sostituire-intorpidito\/\",\"url\":\"https:\/\/statorials.org\/it\/sostituire-intorpidito\/\",\"name\":\"Come sostituire gli elementi in un array NumPy (3 esempi) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-18T03:15:52+00:00\",\"dateModified\":\"2023-07-18T03:15:52+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come sostituire gli elementi in un array NumPy, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/sostituire-intorpidito\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/sostituire-intorpidito\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/sostituire-intorpidito\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come sostituire gli elementi in un array numpy (3 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 sostituire gli elementi in un array NumPy (3 esempi) - Statorials","description":"Questo tutorial spiega come sostituire gli elementi in un array 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\/sostituire-intorpidito\/","og_locale":"it_IT","og_type":"article","og_title":"Come sostituire gli elementi in un array NumPy (3 esempi) - Statorials","og_description":"Questo tutorial spiega come sostituire gli elementi in un array NumPy, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/sostituire-intorpidito\/","og_site_name":"Statorials","article_published_time":"2023-07-18T03:15:52+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"2 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/sostituire-intorpidito\/","url":"https:\/\/statorials.org\/it\/sostituire-intorpidito\/","name":"Come sostituire gli elementi in un array NumPy (3 esempi) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-18T03:15:52+00:00","dateModified":"2023-07-18T03:15:52+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come sostituire gli elementi in un array NumPy, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/sostituire-intorpidito\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/sostituire-intorpidito\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/sostituire-intorpidito\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come sostituire gli elementi in un array numpy (3 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\/3317"}],"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=3317"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3317\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}