{"id":2361,"date":"2023-07-22T14:52:06","date_gmt":"2023-07-22T14:52:06","guid":{"rendered":"https:\/\/statorials.org\/pt\/erro-de-tipo-nao-pode-realizar-reducao-com-tipo-flexivel\/"},"modified":"2023-07-22T14:52:06","modified_gmt":"2023-07-22T14:52:06","slug":"erro-de-tipo-nao-pode-realizar-reducao-com-tipo-flexivel","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/erro-de-tipo-nao-pode-realizar-reducao-com-tipo-flexivel\/","title":{"rendered":"Como corrigir: typeerror: n\u00e3o \u00e9 poss\u00edvel reduzir com tipo flex\u00edvel"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Um erro que voc\u00ea pode encontrar ao usar Python \u00e9:<\/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;\">Este erro ocorre quando voc\u00ea tenta realizar um c\u00e1lculo em um objeto em Python que n\u00e3o \u00e9 num\u00e9rico.<\/span><\/p>\n<p> <span style=\"color: #000000;\">O exemplo a seguir mostra como corrigir esse erro na pr\u00e1tica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Como reproduzir o erro<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Suponha que temos o seguinte 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;\">Estamos recebendo um <strong>TypeError<\/strong> porque tentamos calcular a mediana de uma lista de valores de string.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Como corrigir o erro<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">A maneira mais f\u00e1cil de corrigir esse erro \u00e9 simplesmente converter o array NumPy em um objeto flutuante para que possamos realizar opera\u00e7\u00f5es matem\u00e1ticas nele.<\/span><\/p>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como fazer isso:<\/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;\">Agora podemos realizar opera\u00e7\u00f5es matem\u00e1ticas no 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;\">Observe que n\u00e3o recebemos nenhum erro porque o array NumPy \u00e9 um objeto flutuante, o que significa que podemos realizar opera\u00e7\u00f5es matem\u00e1ticas nele.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Os tutoriais a seguir explicam como corrigir outros erros comuns em Python:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/pt\/erro-de-chave-do-pandas\/\" target=\"_blank\" rel=\"noopener\">Como corrigir KeyError em Pandas<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/valueerror-nao-pode-converter-float-nan-em-inteiro\/\" target=\"_blank\" rel=\"noopener\">Como corrigir: ValueError: n\u00e3o \u00e9 poss\u00edvel converter float NaN em int<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/os-operandos-nao-puderam-ser-transmitidos-com-os-formularios\/\" target=\"_blank\" rel=\"noopener\">Como corrigir: ValueError: os operandos n\u00e3o puderam ser transmitidos com formas<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Um erro que voc\u00ea pode encontrar ao usar Python \u00e9: ValueError : cannot perform reduce with flexible type Este erro ocorre quando voc\u00ea tenta realizar um c\u00e1lculo em um objeto em Python que n\u00e3o \u00e9 num\u00e9rico. O exemplo a seguir mostra como corrigir esse erro na pr\u00e1tica. Como reproduzir o erro Suponha que temos o [&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":[],"class_list":["post-2361","post","type-post","status-publish","format-standard","hentry","category-guia"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Como corrigir: TypeError: n\u00e3o \u00e9 poss\u00edvel recolher com tipo flex\u00edvel - Statorials<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como corrigir o seguinte erro em Python: TypeError: N\u00e3o \u00e9 poss\u00edvel reduzir com tipo flex\u00edvel.\" \/>\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\/pt\/erro-de-tipo-nao-pode-realizar-reducao-com-tipo-flexivel\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como corrigir: TypeError: n\u00e3o \u00e9 poss\u00edvel recolher com tipo flex\u00edvel - Statorials\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como corrigir o seguinte erro em Python: TypeError: N\u00e3o \u00e9 poss\u00edvel reduzir com tipo flex\u00edvel.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/erro-de-tipo-nao-pode-realizar-reducao-com-tipo-flexivel\/\" \/>\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=\"Dr. benjamim anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr. benjamim anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo estimado de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/erro-de-tipo-nao-pode-realizar-reducao-com-tipo-flexivel\/\",\"url\":\"https:\/\/statorials.org\/pt\/erro-de-tipo-nao-pode-realizar-reducao-com-tipo-flexivel\/\",\"name\":\"Como corrigir: TypeError: n\u00e3o \u00e9 poss\u00edvel recolher com tipo flex\u00edvel - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-22T14:52:06+00:00\",\"dateModified\":\"2023-07-22T14:52:06+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como corrigir o seguinte erro em Python: TypeError: N\u00e3o \u00e9 poss\u00edvel reduzir com tipo flex\u00edvel.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/erro-de-tipo-nao-pode-realizar-reducao-com-tipo-flexivel\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/erro-de-tipo-nao-pode-realizar-reducao-com-tipo-flexivel\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/erro-de-tipo-nao-pode-realizar-reducao-com-tipo-flexivel\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como corrigir: typeerror: n\u00e3o \u00e9 poss\u00edvel reduzir com tipo flex\u00edvel\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/pt\/#website\",\"url\":\"https:\/\/statorials.org\/pt\/\",\"name\":\"Statorials\",\"description\":\"O seu guia para a literacia estat\u00edstica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/pt\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-PT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\",\"name\":\"Dr. benjamim anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr. benjamim anderson\"},\"description\":\"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais\",\"sameAs\":[\"https:\/\/statorials.org\/pt\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Como corrigir: TypeError: n\u00e3o \u00e9 poss\u00edvel recolher com tipo flex\u00edvel - Statorials","description":"Este tutorial explica como corrigir o seguinte erro em Python: TypeError: N\u00e3o \u00e9 poss\u00edvel reduzir com tipo flex\u00edvel.","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\/pt\/erro-de-tipo-nao-pode-realizar-reducao-com-tipo-flexivel\/","og_locale":"pt_PT","og_type":"article","og_title":"Como corrigir: TypeError: n\u00e3o \u00e9 poss\u00edvel recolher com tipo flex\u00edvel - Statorials","og_description":"Este tutorial explica como corrigir o seguinte erro em Python: TypeError: N\u00e3o \u00e9 poss\u00edvel reduzir com tipo flex\u00edvel.","og_url":"https:\/\/statorials.org\/pt\/erro-de-tipo-nao-pode-realizar-reducao-com-tipo-flexivel\/","og_site_name":"Statorials","article_published_time":"2023-07-22T14:52:06+00:00","author":"Dr. benjamim anderson","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Dr. benjamim anderson","Tempo estimado de leitura":"2 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pt\/erro-de-tipo-nao-pode-realizar-reducao-com-tipo-flexivel\/","url":"https:\/\/statorials.org\/pt\/erro-de-tipo-nao-pode-realizar-reducao-com-tipo-flexivel\/","name":"Como corrigir: TypeError: n\u00e3o \u00e9 poss\u00edvel recolher com tipo flex\u00edvel - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-22T14:52:06+00:00","dateModified":"2023-07-22T14:52:06+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como corrigir o seguinte erro em Python: TypeError: N\u00e3o \u00e9 poss\u00edvel reduzir com tipo flex\u00edvel.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/erro-de-tipo-nao-pode-realizar-reducao-com-tipo-flexivel\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/erro-de-tipo-nao-pode-realizar-reducao-com-tipo-flexivel\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/erro-de-tipo-nao-pode-realizar-reducao-com-tipo-flexivel\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como corrigir: typeerror: n\u00e3o \u00e9 poss\u00edvel reduzir com tipo flex\u00edvel"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/pt\/#website","url":"https:\/\/statorials.org\/pt\/","name":"Statorials","description":"O seu guia para a literacia estat\u00edstica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/pt\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-PT"},{"@type":"Person","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666","name":"Dr. benjamim anderson","image":{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr. benjamim anderson"},"description":"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais","sameAs":["https:\/\/statorials.org\/pt"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/2361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/comments?post=2361"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/2361\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=2361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=2361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=2361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}