{"id":2362,"date":"2023-07-22T14:52:06","date_gmt":"2023-07-22T14:52:06","guid":{"rendered":"https:\/\/statorials.org\/it\/lerrore-di-tipo-non-puo-eseguire-la-riduzione-con-il-tipo-flessibile\/"},"modified":"2023-07-22T14:52:06","modified_gmt":"2023-07-22T14:52:06","slug":"lerrore-di-tipo-non-puo-eseguire-la-riduzione-con-il-tipo-flessibile","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/lerrore-di-tipo-non-puo-eseguire-la-riduzione-con-il-tipo-flessibile\/","title":{"rendered":"Come risolvere il problema: typeerror: impossibile ridurre con il tipo flessibile"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Un errore che potresti riscontrare quando usi Python \u00e8:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #ff0000;\">ValueError<\/span> : cannot perform reduce with flexible type\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo errore si verifica quando tenti di eseguire un calcolo su un oggetto in Python che non \u00e8 numerico.<\/span><\/p>\n<p> <span style=\"color: #000000;\">L&#8217;esempio seguente mostra come correggere questo errore nella pratica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Come riprodurre l&#8217;errore<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di avere 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;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#define NumPy array of values\n<\/span>data = np. <span style=\"color: #3366ff;\">array<\/span> (['1', '2', '3', '4', '7', '9', '10', '12'])\n\n<span style=\"color: #008080;\">#attempt to calculate median of values\n<\/span>n.p. <span style=\"color: #3366ff;\">median<\/span> (data)\n\n<span style=\"color: #ff0000;\">TypeError<\/span> : cannot perform reduce with flexible type\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Stiamo ricevendo un <strong>TypeError<\/strong> perch\u00e9 abbiamo provato a calcolare la mediana di un elenco di valori stringa.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Come correggere l&#8217;errore<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il modo pi\u00f9 semplice per correggere questo errore \u00e8 semplicemente convertire l&#8217;array NumPy in un oggetto float in modo da poter eseguire operazioni matematiche su di esso.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come eseguire questa operazione:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#convert NumPy array of string values to float values<\/span>\ndata_new = data. <span style=\"color: #3366ff;\">astype<\/span> (float)\n\n<span style=\"color: #008080;\">#view updated NumPy array\n<\/span>data_new\n<\/span>\n<span style=\"color: #000000;\">array([ 1., 2., 3., 4., 7., 9., 10., 12.])\n\n<span style=\"color: #008080;\">#check data type of array<\/span>\ndata_new. <span style=\"color: #3366ff;\">dtype\n\n<\/span>dtype('float64')\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Ora possiamo eseguire operazioni matematiche sull&#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;\">#calculate median value of array\n<\/span>n.p. <span style=\"color: #3366ff;\">median<\/span> (data_new)\n\n5.5\n\n<span style=\"color: #008080;\">#calculate mean value of array\n<\/span>n.p. <span style=\"color: #3366ff;\">mean<\/span> (data_new)\n\n6.0\n\n<span style=\"color: #008080;\">#calculate max value of array\n<\/span>n.p. <span style=\"color: #3366ff;\">max<\/span> (data_new)\n\n12.0<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che non riceviamo alcun errore perch\u00e9 l&#8217;array NumPy \u00e8 un oggetto float, il che significa che possiamo eseguire operazioni matematiche su di esso.<\/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 correggere altri errori comuni in Python:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/errore-chiave-panda\/\" target=\"_blank\" rel=\"noopener\">Come correggere l&#8217;errore chiave nei Panda<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/valueerror-non-puo-convertire-float-nan-in-intero\/\" target=\"_blank\" rel=\"noopener\">Come risolvere il problema: ValueError: impossibile convertire float NaN in int<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/non-e-stato-possibile-trasmettere-gli-operandi-con-i-moduli\/\" target=\"_blank\" rel=\"noopener\">Come risolvere il problema: ValueError: non \u00e8 stato possibile trasmettere gli operandi con le forme<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Un errore che potresti riscontrare quando usi Python \u00e8: ValueError : cannot perform reduce with flexible type Questo errore si verifica quando tenti di eseguire un calcolo su un oggetto in Python che non \u00e8 numerico. L&#8217;esempio seguente mostra come correggere questo errore nella pratica. Come riprodurre l&#8217;errore Supponiamo di avere il seguente array NumPy: [&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 risolvere il problema: TypeError: impossibile comprimere con il tipo flessibile - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come correggere il seguente errore in Python: TypeError: impossibile ridurre con tipo flessibile.\" \/>\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\/lerrore-di-tipo-non-puo-eseguire-la-riduzione-con-il-tipo-flessibile\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come risolvere il problema: TypeError: impossibile comprimere con il tipo flessibile - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come correggere il seguente errore in Python: TypeError: impossibile ridurre con tipo flessibile.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/lerrore-di-tipo-non-puo-eseguire-la-riduzione-con-il-tipo-flessibile\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-22T14:52:06+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\/lerrore-di-tipo-non-puo-eseguire-la-riduzione-con-il-tipo-flessibile\/\",\"url\":\"https:\/\/statorials.org\/it\/lerrore-di-tipo-non-puo-eseguire-la-riduzione-con-il-tipo-flessibile\/\",\"name\":\"Come risolvere il problema: TypeError: impossibile comprimere con il tipo flessibile - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-22T14:52:06+00:00\",\"dateModified\":\"2023-07-22T14:52:06+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come correggere il seguente errore in Python: TypeError: impossibile ridurre con tipo flessibile.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/lerrore-di-tipo-non-puo-eseguire-la-riduzione-con-il-tipo-flessibile\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/lerrore-di-tipo-non-puo-eseguire-la-riduzione-con-il-tipo-flessibile\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/lerrore-di-tipo-non-puo-eseguire-la-riduzione-con-il-tipo-flessibile\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come risolvere il problema: typeerror: impossibile ridurre con il tipo flessibile\"}]},{\"@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 risolvere il problema: TypeError: impossibile comprimere con il tipo flessibile - Statorials","description":"Questo tutorial spiega come correggere il seguente errore in Python: TypeError: impossibile ridurre con tipo flessibile.","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\/lerrore-di-tipo-non-puo-eseguire-la-riduzione-con-il-tipo-flessibile\/","og_locale":"it_IT","og_type":"article","og_title":"Come risolvere il problema: TypeError: impossibile comprimere con il tipo flessibile - Statorials","og_description":"Questo tutorial spiega come correggere il seguente errore in Python: TypeError: impossibile ridurre con tipo flessibile.","og_url":"https:\/\/statorials.org\/it\/lerrore-di-tipo-non-puo-eseguire-la-riduzione-con-il-tipo-flessibile\/","og_site_name":"Statorials","article_published_time":"2023-07-22T14:52:06+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\/lerrore-di-tipo-non-puo-eseguire-la-riduzione-con-il-tipo-flessibile\/","url":"https:\/\/statorials.org\/it\/lerrore-di-tipo-non-puo-eseguire-la-riduzione-con-il-tipo-flessibile\/","name":"Come risolvere il problema: TypeError: impossibile comprimere con il tipo flessibile - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-22T14:52:06+00:00","dateModified":"2023-07-22T14:52:06+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come correggere il seguente errore in Python: TypeError: impossibile ridurre con tipo flessibile.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/lerrore-di-tipo-non-puo-eseguire-la-riduzione-con-il-tipo-flessibile\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/lerrore-di-tipo-non-puo-eseguire-la-riduzione-con-il-tipo-flessibile\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/lerrore-di-tipo-non-puo-eseguire-la-riduzione-con-il-tipo-flessibile\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come risolvere il problema: typeerror: impossibile ridurre con il tipo flessibile"}]},{"@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\/2362"}],"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=2362"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2362\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=2362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=2362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=2362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}