{"id":3241,"date":"2023-07-18T12:33:46","date_gmt":"2023-07-18T12:33:46","guid":{"rendered":"https:\/\/statorials.org\/pt\/filtro-digital\/"},"modified":"2023-07-18T12:33:46","modified_gmt":"2023-07-18T12:33:46","slug":"filtro-digital","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/filtro-digital\/","title":{"rendered":"Como filtrar um array numpy (4 exemplos)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Voc\u00ea pode usar os seguintes m\u00e9todos para filtrar os valores de um array NumPy:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>M\u00e9todo 1: Filtrar valores com base em uma \u00fanica condi\u00e7\u00e3o<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#filter for values less than 5<\/span>\nmy_array[my_array &lt; <span style=\"color: #008000;\">5<\/span> ]\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>M\u00e9todo 2: Filtrar valores usando a condi\u00e7\u00e3o \u201cOR\u201d<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#filter for values less than 5 <em>or<\/em> greater than 9<\/span>\nmy_array[(my_array &lt; <span style=\"color: #008000;\">5<\/span> ) | (my_array &gt; <span style=\"color: #008000;\">9<\/span> )]\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>M\u00e9todo 3: Filtrar valores usando a condi\u00e7\u00e3o \u201cAND\u201d<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#filter for values greater than 5 <i>and<\/i> less than 9<\/span>\nmy_array[(my_array &gt; <span style=\"color: #008000;\">5<\/span> ) &amp; (my_array &lt; <span style=\"color: #008000;\">9<\/span> )]<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>M\u00e9todo 4: Filtre os valores contidos na lista<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#filter for values that are equal to 2, 3, 5, or 12<\/span>\nmy_array[np. <span style=\"color: #3366ff;\">in1d<\/span> (my_array, [2, 3, 5, 12])]\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Este tutorial explica como usar cada m\u00e9todo na pr\u00e1tica com o seguinte array NumPy:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n\n<span style=\"color: #008080;\">#create NumPy array\n<\/span>my_array = np. <span style=\"color: #3366ff;\">array<\/span> ([1, 2, 2, 3, 5, 6, 7, 10, 12, 14])\n\n<span style=\"color: #008080;\">#view NumPy array<\/span>\nmy_array\n\narray([ 1, 2, 2, 3, 5, 6, 7, 10, 12, 14])\n<\/strong><\/span><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Exemplo 1: Filtrar valores com base em uma condi\u00e7\u00e3o<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como filtrar os valores da matriz NumPy com base em uma \u00fanica condi\u00e7\u00e3o:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#filter for values less than 5\n<\/span>my_array[(my_array &lt; <span style=\"color: #008000;\">5<\/span> )]\n\narray([1, 2, 2, 3])\n\n<span style=\"color: #008080;\">#filter for values greater than 5\n<\/span>my_array[(my_array &gt; <span style=\"color: #008000;\">5<\/span> )]\n\narray([6,7,10,12,14])\n\n<span style=\"color: #008080;\">#filter for values equal to 5\n<\/span>my_array[(my_array == <span style=\"color: #008000;\">5<\/span> )]\n\narray([5])\n<\/strong><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Exemplo 2: Filtrar valores usando a condi\u00e7\u00e3o \u201cOR\u201d<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como filtrar os valores do array NumPy usando uma condi\u00e7\u00e3o \u201cOR\u201d:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#filter for values less than 5 <em>or<\/em> greater than 9<\/span>\nmy_array[(my_array &lt; <span style=\"color: #008000;\">5<\/span> ) | (my_array &gt; <span style=\"color: #008000;\">9<\/span> )]\n\narray([ 1, 2, 2, 3, 10, 12, 14])\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Este filtro retorna valores do array NumPy menores que 5 <strong>ou<\/strong> maiores que 9.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Exemplo 3: Filtrar valores usando a condi\u00e7\u00e3o \u201cAND\u201d<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como filtrar os valores do array NumPy usando uma condi\u00e7\u00e3o \u201cAND\u201d:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#filter for values greater than 5 <i>and<\/i> less than 9<\/span>\nmy_array[(my_array &gt; <span style=\"color: #008000;\">5<\/span> ) &amp; (my_array &lt; <span style=\"color: #008000;\">9<\/span> )]\n\narray([6, 7])\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Este filtro retorna valores do array NumPy maiores que 5 <b>e<\/b> menores que 9.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Exemplo 4: filtre os valores contidos na lista<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como filtrar os valores do array NumPy contidos em uma lista:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#filter for values that are equal to 2, 3, 5, or 12<\/span>\nmy_array[np. <span style=\"color: #3366ff;\">in1d<\/span> (my_array, [2, 3, 5, 12])]\n\narray([ 2, 2, 3, 5, 12])\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Este filtro retorna apenas valores iguais a 2, 3, 5 ou 12.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : Voc\u00ea pode encontrar a documenta\u00e7\u00e3o completa para a fun\u00e7\u00e3o NumPy <strong>in1d()<\/strong> <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.in1d.html\" target=\"_blank\" rel=\"noopener\">aqui<\/a> .<\/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 realizar outras opera\u00e7\u00f5es comuns de filtragem em Python:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/pt\/linhas-de-filtro-do-pandas-contendo-string\/\" target=\"_blank\" rel=\"noopener\">Como filtrar linhas do Pandas DataFrame que cont\u00eam uma string espec\u00edfica<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/pandas-filtram-multiplas-condicoes\/\" target=\"_blank\" rel=\"noopener\">Como filtrar um DataFrame do Pandas em m\u00faltiplas condi\u00e7\u00f5es<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/pandas-ausentes\/\" target=\"_blank\" rel=\"noopener\">Como usar o filtro \u201cNOT IN\u201d no Pandas DataFrame<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Voc\u00ea pode usar os seguintes m\u00e9todos para filtrar os valores de um array NumPy: M\u00e9todo 1: Filtrar valores com base em uma \u00fanica condi\u00e7\u00e3o #filter for values less than 5 my_array[my_array &lt; 5 ] M\u00e9todo 2: Filtrar valores usando a condi\u00e7\u00e3o \u201cOR\u201d #filter for values less than 5 or greater than 9 my_array[(my_array &lt; 5 [&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-3241","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 filtrar um array NumPy (4 exemplos) - Estatoriais<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como filtrar um array NumPy, com v\u00e1rios exemplos.\" \/>\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\/filtro-digital\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como filtrar um array NumPy (4 exemplos) - Estatoriais\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como filtrar um array NumPy, com v\u00e1rios exemplos.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/filtro-digital\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-18T12:33:46+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\/filtro-digital\/\",\"url\":\"https:\/\/statorials.org\/pt\/filtro-digital\/\",\"name\":\"Como filtrar um array NumPy (4 exemplos) - Estatoriais\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-18T12:33:46+00:00\",\"dateModified\":\"2023-07-18T12:33:46+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como filtrar um array NumPy, com v\u00e1rios exemplos.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/filtro-digital\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/filtro-digital\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/filtro-digital\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como filtrar um array numpy (4 exemplos)\"}]},{\"@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 filtrar um array NumPy (4 exemplos) - Estatoriais","description":"Este tutorial explica como filtrar um array NumPy, com v\u00e1rios exemplos.","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\/filtro-digital\/","og_locale":"pt_PT","og_type":"article","og_title":"Como filtrar um array NumPy (4 exemplos) - Estatoriais","og_description":"Este tutorial explica como filtrar um array NumPy, com v\u00e1rios exemplos.","og_url":"https:\/\/statorials.org\/pt\/filtro-digital\/","og_site_name":"Statorials","article_published_time":"2023-07-18T12:33:46+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\/filtro-digital\/","url":"https:\/\/statorials.org\/pt\/filtro-digital\/","name":"Como filtrar um array NumPy (4 exemplos) - Estatoriais","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-18T12:33:46+00:00","dateModified":"2023-07-18T12:33:46+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como filtrar um array NumPy, com v\u00e1rios exemplos.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/filtro-digital\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/filtro-digital\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/filtro-digital\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como filtrar um array numpy (4 exemplos)"}]},{"@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\/3241","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=3241"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/3241\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=3241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=3241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=3241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}