{"id":3304,"date":"2023-07-18T04:52:04","date_gmt":"2023-07-18T04:52:04","guid":{"rendered":"https:\/\/statorials.org\/it\/conteggio-numpy-unico\/"},"modified":"2023-07-18T04:52:04","modified_gmt":"2023-07-18T04:52:04","slug":"conteggio-numpy-unico","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/conteggio-numpy-unico\/","title":{"rendered":"Come contare valori univoci nell&#39;array numpy (3 esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare i seguenti metodi per contare valori univoci in un array NumPy:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: mostra valori univoci<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>n.p. <span style=\"color: #3366ff;\">single<\/span> (my_array)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: contare il numero di valori univoci<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">len<\/span> (np. <span style=\"color: #3366ff;\">unique<\/span> (my_array))<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 3: contare le occorrenze di ciascun valore univoco<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>n.p. <span style=\"color: #3366ff;\">unique<\/span> (my_array, return_counts= <span style=\"color: #008000;\">True<\/span> )<\/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;\"> <strong><span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n\n<span style=\"color: #008080;\">#create NumPy array<\/span>\nmy_array = np. <span style=\"color: #3366ff;\">array<\/span> ([1, 3, 3, 4, 4, 7, 8, 8])\n<\/strong><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 1: mostra valori univoci<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come visualizzare valori univoci nell&#8217;array NumPy:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#display unique values\n<\/span>n.p. <span style=\"color: #3366ff;\">single<\/span> (my_array)\n\narray([1, 3, 4, 7, 8])\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Dall&#8217;output, possiamo vedere ciascuno dei valori univoci nell&#8217;array NumPy: 1, 3, 4, 7, 8.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 2: contare il numero di valori univoci<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come contare il numero totale di valori univoci nell&#8217;array NumPy:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\"><span style=\"color: #008080;\">#display total number of unique values<\/span>\nlen<\/span> (np. <span style=\"color: #3366ff;\">unique<\/span> (my_array))\n\n5<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Dall&#8217;output, possiamo vedere che ci sono <strong>5<\/strong> valori univoci nell&#8217;array NumPy.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 3: contare le occorrenze di ciascun valore univoco<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come contare il numero di occorrenze di ciascun valore univoco nell&#8217;array NumPy:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#count occurrences of each unique value\n<\/span>n.p. <span style=\"color: #3366ff;\">unique<\/span> (my_array, return_counts= <span style=\"color: #008000;\">True<\/span> )\n\n(array([1, 3, 4, 7, 8]), array([1, 2, 2, 1, 2]))\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">La prima tabella nell&#8217;output mostra i valori univoci e la seconda tabella mostra il conteggio di ciascun valore univoco.<\/span><\/span><\/p>\n<p> <span style=\"color: #000000;\">Possiamo usare il seguente codice per stampare questo output in un formato pi\u00f9 facile da leggere:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#get unique values and counts of each value\n<\/span>unique, counts = np. <span style=\"color: #3366ff;\">unique<\/span> (my_array, return_counts= <span style=\"color: #008000;\">True<\/span> )\n\n<span style=\"color: #008080;\">#display unique values and counts side by side\n<\/span><span style=\"color: #008000;\">print<\/span> ( <span style=\"color: #3366ff;\">np.asarray<\/span> ((unique,counts)). <span style=\"color: #3366ff;\">T<\/span> )\n\n[[1 1]\n [3 2]\n [4 2]\n [7 1]\n [8 2]]\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Dal risultato possiamo vedere:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">Il valore 1 appare <strong>1<\/strong> volta.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Il valore 3 appare <strong>due volte<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">Il valore 4 appare <strong>due volte<\/strong> .<\/span><\/li>\n<li> <span style=\"color: #000000;\">Il valore 7 appare <strong>1<\/strong> volta.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Il valore 8 appare <strong>due volte<\/strong> .<\/span><\/li>\n<\/ul>\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 Python:<\/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\/carta-digitale\/\" target=\"_blank\" rel=\"noopener\">Come mappare una funzione su un array NumPy<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/numpy-ordina-array-per-colonna\/\" target=\"_blank\" rel=\"noopener\">Come ordinare un array NumPy per colonna<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare i seguenti metodi per contare valori univoci in un array NumPy: Metodo 1: mostra valori univoci n.p. single (my_array) Metodo 2: contare il numero di valori univoci len (np. unique (my_array)) Metodo 3: contare le occorrenze di ciascun valore univoco n.p. unique (my_array, return_counts= True ) I seguenti esempi mostrano come utilizzare [&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 contare valori univoci in un array NumPy (3 esempi) - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come contare valori univoci 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\/conteggio-numpy-unico\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come contare valori univoci in un array NumPy (3 esempi) - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come contare valori univoci in un array NumPy, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/conteggio-numpy-unico\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-18T04:52:04+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\/conteggio-numpy-unico\/\",\"url\":\"https:\/\/statorials.org\/it\/conteggio-numpy-unico\/\",\"name\":\"Come contare valori univoci in un array NumPy (3 esempi) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-18T04:52:04+00:00\",\"dateModified\":\"2023-07-18T04:52:04+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come contare valori univoci in un array NumPy, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/conteggio-numpy-unico\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/conteggio-numpy-unico\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/conteggio-numpy-unico\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come contare valori univoci nell&#39;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 contare valori univoci in un array NumPy (3 esempi) - Statorials","description":"Questo tutorial spiega come contare valori univoci 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\/conteggio-numpy-unico\/","og_locale":"it_IT","og_type":"article","og_title":"Come contare valori univoci in un array NumPy (3 esempi) - Statorials","og_description":"Questo tutorial spiega come contare valori univoci in un array NumPy, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/conteggio-numpy-unico\/","og_site_name":"Statorials","article_published_time":"2023-07-18T04:52:04+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\/conteggio-numpy-unico\/","url":"https:\/\/statorials.org\/it\/conteggio-numpy-unico\/","name":"Come contare valori univoci in un array NumPy (3 esempi) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-18T04:52:04+00:00","dateModified":"2023-07-18T04:52:04+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come contare valori univoci in un array NumPy, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/conteggio-numpy-unico\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/conteggio-numpy-unico\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/conteggio-numpy-unico\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come contare valori univoci nell&#39;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\/3304"}],"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=3304"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3304\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}