{"id":2409,"date":"2023-07-22T09:56:32","date_gmt":"2023-07-22T09:56:32","guid":{"rendered":"https:\/\/statorials.org\/it\/condizioni-numpy-o-multiple\/"},"modified":"2023-07-22T09:56:32","modified_gmt":"2023-07-22T09:56:32","slug":"condizioni-numpy-o-multiple","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/condizioni-numpy-o-multiple\/","title":{"rendered":"Come utilizzare numpy where() con pi\u00f9 condizioni"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare i seguenti metodi per utilizzare la funzione <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.where.html\" target=\"_blank\" rel=\"noopener\">NumPywhere()<\/a> con pi\u00f9 condizioni:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: utilizzare Where() con OR<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#select values less than five <em>or<\/em> greater than 20<\/span>\nx[np. <span style=\"color: #3366ff;\">where<\/span> ((x <span style=\"color: #800080;\">&lt;<\/span> 5) <span style=\"color: #800080;\">|<\/span> (x <span style=\"color: #800080;\">&gt;<\/span> 20))]\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: utilizzare Where() con AND<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#select values greater than five <i>and<\/i> less than 20<\/span>\nx[np. <span style=\"color: #3366ff;\">where<\/span> ((x <span style=\"color: #800080;\">&gt;<\/span> 5) <span style=\"color: #800080;\">&amp;<\/span> (x <span style=\"color: #800080;\">&lt;<\/span> 20))]<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">L&#8217;esempio seguente mostra come utilizzare ciascun metodo nella pratica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Metodo 1: utilizzare Where() con OR<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come selezionare ciascun valore in un array NumPy inferiore a 5 <strong>o<\/strong> maggiore di 20:<\/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;\">#define NumPy array of values\n<span style=\"color: #000000;\">x = np. <span style=\"color: #3366ff;\">array<\/span> ([1, 3, 3, 6, 7, 9, 12, 13, 15, 18, 20, 22])\n\n<span style=\"color: #008080;\">#select values that meet one of two conditions\n<\/span>x[np. <span style=\"color: #3366ff;\">where<\/span> ((x <span style=\"color: #800080;\">&lt;<\/span> 5) <span style=\"color: #800080;\">|<\/span> (x <span style=\"color: #800080;\">&gt;<\/span> 20))]\n\narray([ 1, 3, 3, 22])\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che quattro valori nell&#8217;array NumPy erano inferiori a 5 <strong>o<\/strong> superiori a 20.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Puoi anche utilizzare la funzione <strong>dimensione<\/strong> per trovare semplicemente quanti valori soddisfano una delle condizioni:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#find number of values that are less than 5 or greater than 20<\/span>\n(x[np. <span style=\"color: #3366ff;\">where<\/span> ((x <span style=\"color: #800080;\">&lt;<\/span> 5) <span style=\"color: #800080;\">|<\/span> (x <span style=\"color: #800080;\">&gt;<\/span> 20))]). <span style=\"color: #3366ff;\">size\n\n<\/span>4<\/span><\/span><\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Metodo 2: utilizzare Where() con AND<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come selezionare ciascun valore da un array NumPy maggiore di 5 <b>e<\/b> minore di 20:<\/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;\">#define NumPy array of values\n<span style=\"color: #000000;\">x = np. <span style=\"color: #3366ff;\">array<\/span> ([1, 3, 3, 6, 7, 9, 12, 13, 15, 18, 20, 22])\n\n<span style=\"color: #008080;\">#select values that meet two conditions\n<\/span>x[np. <span style=\"color: #3366ff;\">where<\/span> ((x <span style=\"color: #800080;\">&gt;<\/span> 5) <span style=\"color: #800080;\">&amp;<\/span> (x <span style=\"color: #800080;\">&lt;<\/span> 20))]\n\narray([6, 7, 9, 12, 13, 15, 18])\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">L&#8217;array di output mostra i sette valori dell&#8217;array NumPy originale maggiori di 5 <strong>e<\/strong> minori di 20.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Ancora una volta, puoi utilizzare la funzione <strong>dimensione<\/strong> per determinare quanti valori soddisfano entrambe le condizioni:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#find number of values that are greater than 5 and less than 20\n<\/span>(x[np. <span style=\"color: #3366ff;\">where<\/span> ((x <span style=\"color: #800080;\">&gt;<\/span> 5) <span style=\"color: #800080;\">&amp;<\/span> (x <span style=\"color: #800080;\">&lt;<\/span> 20))]). <span style=\"color: #3366ff;\">size\n\n<\/span>7<\/span><\/span><\/strong><\/pre>\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\/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 utilizzare la funzione NumPywhere() con pi\u00f9 condizioni: Metodo 1: utilizzare Where() con OR #select values less than five or greater than 20 x[np. where ((x &lt; 5) | (x &gt; 20))] Metodo 2: utilizzare Where() con AND #select values greater than five and less than 20 x[np. where [&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 utilizzare NumPy Where() con pi\u00f9 condizioni \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come utilizzare la funzione NumPywhere() con diverse condizioni, inclusi 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\/condizioni-numpy-o-multiple\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come utilizzare NumPy Where() con pi\u00f9 condizioni \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come utilizzare la funzione NumPywhere() con diverse condizioni, inclusi diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/condizioni-numpy-o-multiple\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-22T09:56:32+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\/condizioni-numpy-o-multiple\/\",\"url\":\"https:\/\/statorials.org\/it\/condizioni-numpy-o-multiple\/\",\"name\":\"Come utilizzare NumPy Where() con pi\u00f9 condizioni \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-22T09:56:32+00:00\",\"dateModified\":\"2023-07-22T09:56:32+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come utilizzare la funzione NumPywhere() con diverse condizioni, inclusi diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/condizioni-numpy-o-multiple\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/condizioni-numpy-o-multiple\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/condizioni-numpy-o-multiple\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come utilizzare numpy where() con pi\u00f9 condizioni\"}]},{\"@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 utilizzare NumPy Where() con pi\u00f9 condizioni \u2013 Statorials","description":"Questo tutorial spiega come utilizzare la funzione NumPywhere() con diverse condizioni, inclusi 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\/condizioni-numpy-o-multiple\/","og_locale":"it_IT","og_type":"article","og_title":"Come utilizzare NumPy Where() con pi\u00f9 condizioni \u2013 Statorials","og_description":"Questo tutorial spiega come utilizzare la funzione NumPywhere() con diverse condizioni, inclusi diversi esempi.","og_url":"https:\/\/statorials.org\/it\/condizioni-numpy-o-multiple\/","og_site_name":"Statorials","article_published_time":"2023-07-22T09:56:32+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\/condizioni-numpy-o-multiple\/","url":"https:\/\/statorials.org\/it\/condizioni-numpy-o-multiple\/","name":"Come utilizzare NumPy Where() con pi\u00f9 condizioni \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-22T09:56:32+00:00","dateModified":"2023-07-22T09:56:32+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come utilizzare la funzione NumPywhere() con diverse condizioni, inclusi diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/condizioni-numpy-o-multiple\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/condizioni-numpy-o-multiple\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/condizioni-numpy-o-multiple\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come utilizzare numpy where() con pi\u00f9 condizioni"}]},{"@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\/2409"}],"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=2409"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2409\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=2409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=2409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=2409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}