{"id":3197,"date":"2023-07-18T17:58:58","date_gmt":"2023-07-18T17:58:58","guid":{"rendered":"https:\/\/statorials.org\/pt\/compare-duas-matrizes-numpy\/"},"modified":"2023-07-18T17:58:58","modified_gmt":"2023-07-18T17:58:58","slug":"compare-duas-matrizes-numpy","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/compare-duas-matrizes-numpy\/","title":{"rendered":"Como comparar dois arrays numpy: com exemplos"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Voc\u00ea pode usar os seguintes m\u00e9todos para comparar os valores de duas matrizes NumPy:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>M\u00e9todo 1: teste se duas matrizes NumPy s\u00e3o iguais no n\u00edvel do elemento<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#test if array A and array B are element-wise equal<\/span>\nn.p. <span style=\"color: #3366ff;\">array_equal<\/span> (A,B)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>M\u00e9todo 2: teste se duas matrizes NumPy s\u00e3o iguais no n\u00edvel do elemento (dentro de uma toler\u00e2ncia)<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#test if array A and array B are element-wise equal (within absolute tolerance of 2)<\/span>\nn.p. <span style=\"color: #3366ff;\">allclose<\/span> (A, B, atol= <span style=\"color: #008080;\">2<\/span> )\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Os exemplos a seguir mostram como usar cada m\u00e9todo na pr\u00e1tica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Exemplo 1: teste se duas matrizes NumPy s\u00e3o iguais no n\u00edvel do elemento<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como usar a fun\u00e7\u00e3o <strong>array_equal()<\/strong> para testar se duas matrizes NumPy s\u00e3o iguais no n\u00edvel do elemento:<\/span><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n<\/span>\n#create two NumPy arrays\n<\/span>A = np. <span style=\"color: #3366ff;\">array<\/span> ([1, 4, 5, 7, 10])\nB = np. <span style=\"color: #3366ff;\">array<\/span> ([1, 4, 5, 7, 10])\n\n<span style=\"color: #008080;\">#test if arrays are element-wise equal\n<\/span>n.p. <span style=\"color: #3366ff;\">array_equal<\/span> (A,B)\n\nTrue<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">A fun\u00e7\u00e3o retorna <strong>True<\/strong> porque ambas as matrizes NumPy t\u00eam o mesmo comprimento com os mesmos valores nas mesmas posi\u00e7\u00f5es.<\/span><\/p>\n<p> <span style=\"color: #000000;\">No entanto, a fun\u00e7\u00e3o retornar\u00e1 <strong>False<\/strong> se os dois arrays NumPy tiverem os mesmos valores, mas em posi\u00e7\u00f5es diferentes:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n<\/span>\n#create two NumPy arrays with same values but in different positions\n<\/span>A = np. <span style=\"color: #3366ff;\">array<\/span> ([1, 4, 5, 7, 10])\nB = np. <span style=\"color: #3366ff;\">array<\/span> ([1, 4, 7, 5, 10])\n\n<span style=\"color: #008080;\">#test if arrays are element-wise equal\n<\/span>n.p. <span style=\"color: #3366ff;\">array_equal<\/span> (A,B)\n\nFalse<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Exemplo 2: teste se duas matrizes NumPy s\u00e3o iguais no n\u00edvel do elemento (dentro da toler\u00e2ncia)<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como usar a fun\u00e7\u00e3o <strong>allclose()<\/strong> para testar se duas matrizes NumPy s\u00e3o iguais no n\u00edvel do elemento dentro de um valor de toler\u00e2ncia de <strong>2<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n<\/span>\n#create two NumPy arrays\n<\/span>A = np. <span style=\"color: #3366ff;\">array<\/span> ([1, 4, 5, 7, 10])\nB = np. <span style=\"color: #3366ff;\">array<\/span> ([1, 4, 7, 8, 10])\n\n<span style=\"color: #008080;\">#test if arrays are element-wise equal (within absolute tolerance of 2)\n<\/span>n.p. <span style=\"color: #3366ff;\">allclose<\/span> (A, B, atol= <span style=\"color: #008000;\">2<\/span> )\n\nTrue<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">A fun\u00e7\u00e3o retorna <strong>True<\/strong> , pois os elementos correspondentes entre cada matriz NumPy est\u00e3o todos dentro de 2 um do outro.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Por exemplo, vemos que os elementos na terceira e quarta posi\u00e7\u00f5es de cada array s\u00e3o diferentes, mas como cada par est\u00e1 separado por 2 valores, a fun\u00e7\u00e3o retorna verdadeiro.<\/span><\/p>\n<p> <span style=\"color: #000000;\">No entanto, se alterarmos o argumento da toler\u00e2ncia absoluta (atol) para <strong>1<\/strong> , a fun\u00e7\u00e3o retornar\u00e1 <strong>False<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">import<\/span> numpy <span style=\"color: #008000;\">as<\/span> np\n<\/span>\n#create two NumPy arrays\n<\/span>A = np. <span style=\"color: #3366ff;\">array<\/span> ([1, 4, 5, 7, 10])\nB = np. <span style=\"color: #3366ff;\">array<\/span> ([1, 4, 7, 8, 10])\n\n<span style=\"color: #008080;\">#test if arrays are element-wise equal (within absolute tolerance of 1)\n<\/span>n.p. <span style=\"color: #3366ff;\">allclose<\/span> (A, B, atol= <span style=\"color: #008000;\">1<\/span> )\n\nFalse<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">A fun\u00e7\u00e3o retorna <b>False<\/b> , pois os elementos correspondentes na terceira posi\u00e7\u00e3o de cada array NumPy n\u00e3o est\u00e3o a 1s de dist\u00e2ncia um do outro.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : Consulte a documenta\u00e7\u00e3o do NumPy para uma explica\u00e7\u00e3o completa das fun\u00e7\u00f5es <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.array_equal.html\" target=\"_blank\" rel=\"noopener\">array_equal<\/a> e <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/generated\/numpy.allclose.html\" target=\"_blank\" rel=\"noopener\">allclose<\/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 tarefas comuns no NumPy:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/pt\/mudanca-entorpecida\/\" target=\"_blank\" rel=\"noopener\">Como mover elementos em um array NumPy<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/conta-digital\/\" target=\"_blank\" rel=\"noopener\">Como contar ocorr\u00eancias de elementos em NumPy<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/modo-digital\/\" target=\"_blank\" rel=\"noopener\">Como calcular o modo do array NumPy<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Voc\u00ea pode usar os seguintes m\u00e9todos para comparar os valores de duas matrizes NumPy: M\u00e9todo 1: teste se duas matrizes NumPy s\u00e3o iguais no n\u00edvel do elemento #test if array A and array B are element-wise equal n.p. array_equal (A,B) M\u00e9todo 2: teste se duas matrizes NumPy s\u00e3o iguais no n\u00edvel do elemento (dentro de [&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-3197","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 comparar dois arrays NumPy (com exemplos) \u2013 Estatologia<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como comparar dois arrays 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\/compare-duas-matrizes-numpy\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como comparar dois arrays NumPy (com exemplos) \u2013 Estatologia\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como comparar dois arrays NumPy, com v\u00e1rios exemplos.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/compare-duas-matrizes-numpy\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-18T17:58:58+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=\"3 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/compare-duas-matrizes-numpy\/\",\"url\":\"https:\/\/statorials.org\/pt\/compare-duas-matrizes-numpy\/\",\"name\":\"Como comparar dois arrays NumPy (com exemplos) \u2013 Estatologia\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-18T17:58:58+00:00\",\"dateModified\":\"2023-07-18T17:58:58+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como comparar dois arrays NumPy, com v\u00e1rios exemplos.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/compare-duas-matrizes-numpy\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/compare-duas-matrizes-numpy\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/compare-duas-matrizes-numpy\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como comparar dois arrays numpy: com 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 comparar dois arrays NumPy (com exemplos) \u2013 Estatologia","description":"Este tutorial explica como comparar dois arrays 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\/compare-duas-matrizes-numpy\/","og_locale":"pt_PT","og_type":"article","og_title":"Como comparar dois arrays NumPy (com exemplos) \u2013 Estatologia","og_description":"Este tutorial explica como comparar dois arrays NumPy, com v\u00e1rios exemplos.","og_url":"https:\/\/statorials.org\/pt\/compare-duas-matrizes-numpy\/","og_site_name":"Statorials","article_published_time":"2023-07-18T17:58:58+00:00","author":"Dr. benjamim anderson","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Dr. benjamim anderson","Tempo estimado de leitura":"3 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pt\/compare-duas-matrizes-numpy\/","url":"https:\/\/statorials.org\/pt\/compare-duas-matrizes-numpy\/","name":"Como comparar dois arrays NumPy (com exemplos) \u2013 Estatologia","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-18T17:58:58+00:00","dateModified":"2023-07-18T17:58:58+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como comparar dois arrays NumPy, com v\u00e1rios exemplos.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/compare-duas-matrizes-numpy\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/compare-duas-matrizes-numpy\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/compare-duas-matrizes-numpy\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como comparar dois arrays numpy: com 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\/3197","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=3197"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/3197\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=3197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=3197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=3197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}