{"id":10588,"date":"2014-03-04T10:15:50","date_gmt":"2014-03-04T15:15:50","guid":{"rendered":"http:\/\/blog.espol.edu.ec\/ccpg1001\/?p=10588"},"modified":"2026-07-17T13:39:03","modified_gmt":"2026-07-17T18:39:03","slug":"s1eva2004tii_t4-matriz-de-paridad","status":"publish","type":"post","link":"https:\/\/blog.espol.edu.ec\/algoritmos101\/fp-s1eva10\/s1eva2004tii_t4-matriz-de-paridad\/","title":{"rendered":"s1Eva2004TII_T4 Matriz de paridad"},"content":{"rendered":"\n<p><em><strong>Ejercicio<\/strong><\/em>: <a href=\"https:\/\/blog.espol.edu.ec\/algoritmos101\/fp-1eva10\/1eva2004tii_t4-matriz-de-paridad\/\" data-type=\"post\" data-id=\"3131\">1Eva2004TII_T4 Matriz de paridad<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"803\" height=\"221\" src=\"http:\/\/blog.espol.edu.ec\/algoritmos101\/files\/2014\/03\/BitParidad01.png\" alt=\"transmisi\u00f3n con Bit Paridad\" class=\"wp-image-16336\" \/><\/figure>\n\n\n\n<p>Establecer una matriz de <strong>n<\/strong> filas y <strong>n+1<\/strong> columnas.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; first-line: 10; title: ; notranslate\" title=\"\">\nmatriz = np.zeros(shape=(n,n+1),dtype=int)\n<\/pre><\/div>\n\n\n<p>Para cada casilla en cada <strong>fila<\/strong> y <strong>columna<\/strong>, generar un <strong>aleatorio<\/strong> de dos posibilidades que m\u00ednimo puede ser cero.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; first-line: 16; title: ; notranslate\" title=\"\">\naleatorio = int(rnd.random()*2)+0\n<\/pre><\/div>\n\n\n<p>con lo que se genera la matriz de n\u00fameros aleatorios.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td colspan=\"7\">Datos<\/td><td>Paridad<\/td><\/tr><tr><td>1<\/td><td>0<\/td><td>1<\/td><td>1<\/td><td>1<\/td><td>0<\/td><td>1<\/td><td><strong>1<\/strong><\/td><\/tr><tr><td>0<\/td><td>1<\/td><td>0<\/td><td>1<\/td><td>1<\/td><td>0<\/td><td>1<\/td><td><strong>0<\/strong><\/td><\/tr><tr><td>1<\/td><td>1<\/td><td>1<\/td><td>1<\/td><td>1<\/td><td>0<\/td><td>1<\/td><td><strong>0<\/strong><\/td><\/tr><tr><td>1<\/td><td>0<\/td><td>1<\/td><td>1<\/td><td>0<\/td><td>1<\/td><td>1<\/td><td><strong>1<\/strong><\/td><\/tr><tr><td>1<\/td><td>0<\/td><td>1<\/td><td>0<\/td><td>0<\/td><td>1<\/td><td>0<\/td><td><strong>1<\/strong><\/td><\/tr><tr><td>1<\/td><td>0<\/td><td>1<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>1<\/td><td><strong>0<\/strong><\/td><\/tr><tr><td>1<\/td><td>1<\/td><td>1<\/td><td>1<\/td><td>0<\/td><td>1<\/td><td>1<\/td><td><strong>0<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image alignright size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"233\" height=\"187\" src=\"http:\/\/blog.espol.edu.ec\/algoritmos101\/files\/2014\/03\/1Eva_IIT2004_T4_MatrizParidad02.png\" alt=\"Matriz Paridad 02\" class=\"wp-image-16338\" \/><\/figure>\n\n\n\n<p>Al finalizar una fila, considere la <strong>suma<\/strong> de <strong>fila<\/strong> para revisar la paridad con el <strong>residuo <\/strong>de la divisi\u00f3n para 2.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; first-line: 20; title: ; notranslate\" title=\"\">\n    residuo = sumafila % 2\n<\/pre><\/div>\n\n\n<p>Si hay <strong>residuo<\/strong> el n\u00famero es impar y se debe escribir el n\u00famero 1 en la \u00faltima casilla de toda la fila (<strong>fila<\/strong>, <strong>n<\/strong>), es decir se completa la paridad.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; first-line: 21; title: ; notranslate\" title=\"\">\n    if residuo: # sumafila es impar\n        matriz&#x5B;fila,n] = 1\n<\/pre><\/div>\n\n\n<p>En el caso opuesto, que no hay <strong>residuo<\/strong>=0, el conteo de '1' ya es par y se deja el valor cero en la \u00faltima casilla.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Algoritmo en Python<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# 1Eva_IIT2004_T4 Matriz de paridad\nimport numpy as np\nimport random as rnd\n\n# INGRESO\nn = 7 # tama\u00f1o matriz\n\n# PROCEDIMIENTO\n# matriz de n filas y n+1 columnas\nmatriz = np.zeros(shape=(n,n+1),dtype=int)\n\n# recorre matriz\nfor fila in range(0,n,1):\n    sumafila = 0\n    for columna in range(0,n,1):\n        aleatorio = int(rnd.random()*2)+0\n        matriz&#x5B;fila,columna] = aleatorio\n        sumafila = sumafila + aleatorio\n    # revisa residuo paridad\n    residuo = sumafila % 2  \n    if residuo: # sumafila es impar\n        matriz&#x5B;fila,n] = 1\n\n# SALIDA\nprint(' Matriz obtenida')\nprint(matriz)\n<\/pre><\/div>\n\n\n<p>resultado:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> Matriz obtenida\n&#091;&#091;0 1 1 1 0 1 1 1]\n &#091;1 1 0 1 0 0 1 0]\n &#091;0 1 1 1 0 1 1 1]\n &#091;1 0 0 1 1 0 1 0]\n &#091;0 1 0 0 0 1 0 0]\n &#091;1 0 0 0 1 1 0 1]\n &#091;1 0 0 0 1 0 1 1]]\n&gt;&gt;&gt; <\/code><\/pre>\n\n\n\n<p><em><strong>Nota<\/strong><\/em>: Observe que la matriz contiene n\u00fameros aleatorios, por lo que el resultado var\u00eda cada vez que se ejecuta el algoritmo.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ejercicio: 1Eva2004TII_T4 Matriz de paridad Establecer una matriz de n filas y n+1 columnas. Para cada casilla en cada fila y columna, generar un aleatorio de dos posibilidades que m\u00ednimo puede ser cero. con lo que se genera la matriz de n\u00fameros aleatorios. Datos Paridad 1 0 1 1 1 0 1 1 0 1 [&hellip;]<\/p>\n","protected":false},"author":8043,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"wp-custom-template-entrada-fp-ejemplos","format":"standard","meta":{"footnotes":""},"categories":[125],"tags":[58,157],"class_list":["post-10588","post","type-post","status-publish","format-standard","hentry","category-fp-s1eva10","tag-ejemplos-python","tag-fundamentos-programacion"],"_links":{"self":[{"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/posts\/10588","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/users\/8043"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/comments?post=10588"}],"version-history":[{"count":7,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/posts\/10588\/revisions"}],"predecessor-version":[{"id":24988,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/posts\/10588\/revisions\/24988"}],"wp:attachment":[{"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/media?parent=10588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/categories?post=10588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/algoritmos101\/wp-json\/wp\/v2\/tags?post=10588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}