{"id":3812,"date":"2023-07-15T09:55:02","date_gmt":"2023-07-15T09:55:02","guid":{"rendered":"https:\/\/statorials.org\/pt\/runif-em-python\/"},"modified":"2023-07-15T09:55:02","modified_gmt":"2023-07-15T09:55:02","slug":"runif-em-python","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/runif-em-python\/","title":{"rendered":"Como usar o equivalente a runif() em python"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Na linguagem de programa\u00e7\u00e3o R, podemos usar a fun\u00e7\u00e3o <strong>runif()<\/strong> para gerar um vetor de valores aleat\u00f3rios que segue uma <a href=\"https:\/\/statorials.org\/pt\/distribuicao-uniforme\/\" target=\"_blank\" rel=\"noopener\">distribui\u00e7\u00e3o uniforme<\/a> com um valor m\u00ednimo e m\u00e1ximo espec\u00edfico.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Por exemplo, o c\u00f3digo a seguir mostra como usar <strong>runif()<\/strong> para criar um vetor de 8 valores aleat\u00f3rios que segue uma distribui\u00e7\u00e3o uniforme com valor m\u00ednimo de 5 e valor m\u00e1ximo de 10:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#make this example reproducible\n<\/span>set. <span style=\"color: #3366ff;\">seeds<\/span> (1)\n\n<span style=\"color: #008080;\">#generate vector of 8 values that follow uniform distribution with min=5 and max=10<\/span>\nrunif(n=8, min=5, max=10)\n\n[1] 6.327543 6.860619 7.864267 9.541039 6.008410 9.491948 9.723376 8.303989\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">O equivalente da fun\u00e7\u00e3o <strong>runif()<\/strong> em Python \u00e9 a fun\u00e7\u00e3o <strong>np.random.uniform()<\/strong> , que usa a seguinte sintaxe b\u00e1sica:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>np.random.uniform(baixo=0, alto=1, tamanho=Nenhum)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Ouro:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>baixo<\/strong> : Valor m\u00ednimo da distribui\u00e7\u00e3o<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>alto<\/strong> : valor m\u00e1ximo da distribui\u00e7\u00e3o<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>tamanho<\/strong> : tamanho da amostra<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">O exemplo a seguir mostra como usar esta fun\u00e7\u00e3o na pr\u00e1tica.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Exemplo: usando o equivalente a runif() em Python<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como usar a fun\u00e7\u00e3o <strong>np.random.uniform()<\/strong> para gerar uma matriz de valores aleat\u00f3rios que segue uma distribui\u00e7\u00e3o uniforme com um valor m\u00ednimo e m\u00e1ximo espec\u00edfico:<\/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;\">#make this example reproducible<\/span>\nn.p. <span style=\"color: #3366ff;\">random<\/span> . <span style=\"color: #3366ff;\">seeds<\/span> (1)\n\n<span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#generate array of 8 values that follow uniform distribution with min=5 and max=10<\/span>\nn.p. <span style=\"color: #3366ff;\">random<\/span> . <span style=\"color: #3366ff;\">uniform<\/span> (low= <span style=\"color: #008000;\">5<\/span> , high= <span style=\"color: #008000;\">10<\/span> , size= <span style=\"color: #008000;\">8<\/span> )\n\narray([7.08511002, 8.60162247, 5.00057187, 6.51166286, 5.73377945,\n       5.46169297, 5.93130106, 6.72780364])\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">O resultado \u00e9 um array NumPy que cont\u00e9m 8 valores gerados a partir de uma distribui\u00e7\u00e3o uniforme com valor m\u00ednimo de 5 e valor m\u00e1ximo de 10.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Voc\u00ea tamb\u00e9m pode criar um histograma usando Matplotlib para visualizar uma distribui\u00e7\u00e3o normal gerada pela fun\u00e7\u00e3o <strong>np.random.uniform()<\/strong> :<\/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<span style=\"color: #008000;\">import<\/span> matplotlib. <span style=\"color: #3366ff;\">pyplot<\/span> <span style=\"color: #008000;\">as<\/span> plt\n\n<span style=\"color: #008080;\">#make this example reproducible<\/span>\nn.p. <span style=\"color: #3366ff;\">random<\/span> . <span style=\"color: #3366ff;\">seeds<\/span> (1)\n\n<span style=\"color: #008080;\">#generate array of 200 values that follow uniform distribution with min=5 and max=10\n<span style=\"color: #000000;\">data = np. <span style=\"color: #3366ff;\">random<\/span> . <span style=\"color: #3366ff;\">uniform<\/span> (low= <span style=\"color: #008000;\">5<\/span> , high= <span style=\"color: #008000;\">10<\/span> , size= <span style=\"color: #008000;\">200<\/span> )\n<\/span>\n#create histogram to visualize distribution of values\n<span style=\"color: #000000;\">plt. <span style=\"color: #3366ff;\">hist<\/span> (data, bins= <span style=\"color: #008000;\">30<\/span> , edgecolor=' <span style=\"color: #ff0000;\">black<\/span> ')\n<\/span><\/span><\/strong><\/pre>\n<p> <strong><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-30905 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/runif1.jpg\" alt=\"\" width=\"553\" height=\"412\" srcset=\"\" sizes=\"auto, \"><\/strong><\/p>\n<p> <span style=\"color: #000000;\">O eixo x mostra os valores da distribui\u00e7\u00e3o e o eixo y mostra a frequ\u00eancia de cada valor.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Observe que o eixo x vai de 5 a 10, pois esses s\u00e3o os valores m\u00ednimo e m\u00e1ximo que especificamos para a distribui\u00e7\u00e3o.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : Voc\u00ea pode encontrar a documenta\u00e7\u00e3o completa da fun\u00e7\u00e3o <strong>np.random.uniform()<\/strong> <a href=\"https:\/\/numpy.org\/doc\/stable\/reference\/random\/generated\/numpy.random.uniform.html\" target=\"_blank\" rel=\"noopener\">aqui<\/a> .<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Os tutoriais a seguir explicam como realizar outras opera\u00e7\u00f5es comuns em pandas:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/pt\/pandas-geram-dados-aleatorios\/\" target=\"_blank\" rel=\"noopener\">Como criar um DataFrame Pandas com dados aleat\u00f3rios<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/estatologia-explica-conceitos-de-forma-simples-e-direta-facilitamos-o-aprendizado-de-estatistica\/\" target=\"_blank\" rel=\"noopener\">Como amostrar linhas aleatoriamente no Pandas<\/a><br \/> Como embaralhar linhas em um DataFrame do Pandas<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Na linguagem de programa\u00e7\u00e3o R, podemos usar a fun\u00e7\u00e3o runif() para gerar um vetor de valores aleat\u00f3rios que segue uma distribui\u00e7\u00e3o uniforme com um valor m\u00ednimo e m\u00e1ximo espec\u00edfico. Por exemplo, o c\u00f3digo a seguir mostra como usar runif() para criar um vetor de 8 valores aleat\u00f3rios que segue uma distribui\u00e7\u00e3o uniforme com valor m\u00ednimo [&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-3812","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 usar o equivalente a runif() em Python \u2013 Estatologia<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como usar a fun\u00e7\u00e3o runif() em Python para replicar a fun\u00e7\u00e3o usada em R, com um exemplo.\" \/>\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\/runif-em-python\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como usar o equivalente a runif() em Python \u2013 Estatologia\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como usar a fun\u00e7\u00e3o runif() em Python para replicar a fun\u00e7\u00e3o usada em R, com um exemplo.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/runif-em-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-15T09:55:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/runif1.jpg\" \/>\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\/runif-em-python\/\",\"url\":\"https:\/\/statorials.org\/pt\/runif-em-python\/\",\"name\":\"Como usar o equivalente a runif() em Python \u2013 Estatologia\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-15T09:55:02+00:00\",\"dateModified\":\"2023-07-15T09:55:02+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como usar a fun\u00e7\u00e3o runif() em Python para replicar a fun\u00e7\u00e3o usada em R, com um exemplo.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/runif-em-python\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/runif-em-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/runif-em-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como usar o equivalente a runif() em python\"}]},{\"@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 usar o equivalente a runif() em Python \u2013 Estatologia","description":"Este tutorial explica como usar a fun\u00e7\u00e3o runif() em Python para replicar a fun\u00e7\u00e3o usada em R, com um exemplo.","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\/runif-em-python\/","og_locale":"pt_PT","og_type":"article","og_title":"Como usar o equivalente a runif() em Python \u2013 Estatologia","og_description":"Este tutorial explica como usar a fun\u00e7\u00e3o runif() em Python para replicar a fun\u00e7\u00e3o usada em R, com um exemplo.","og_url":"https:\/\/statorials.org\/pt\/runif-em-python\/","og_site_name":"Statorials","article_published_time":"2023-07-15T09:55:02+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/runif1.jpg"}],"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\/runif-em-python\/","url":"https:\/\/statorials.org\/pt\/runif-em-python\/","name":"Como usar o equivalente a runif() em Python \u2013 Estatologia","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-15T09:55:02+00:00","dateModified":"2023-07-15T09:55:02+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como usar a fun\u00e7\u00e3o runif() em Python para replicar a fun\u00e7\u00e3o usada em R, com um exemplo.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/runif-em-python\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/runif-em-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/runif-em-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como usar o equivalente a runif() em python"}]},{"@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\/3812","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=3812"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/3812\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=3812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=3812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=3812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}