<?xml version="1.0" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>
            Python Hispano
        </title>
        <link>
            http://planet.python-hispano.org/
        </link>
        <language>
            es
        </language>
        <description>
            miembros de Python Hispano
        </description>
        <atom:link href="http://planet.python-hispano.org/rss.xml" rel="self" type="application/rss+xml"/>
        <item>
            <guid isPermaLink="false">
                http://pybonacci.wordpress.com/?p=262
            </guid>
            <title>
                Pybonacci: Manual de introducci&amp;#243;n a matplotlib.pyplot (II): Creando y manejando ventanas y configurando la sesi&amp;#243;n
            </title>
            <pubDate>
                Sat, 19 May 2012 19:31:43 GMT
            </pubDate>
            <link>
                http://pybonacci.wordpress.com/2012/05/19/manual-de-introduccion-a-matplotlib-pyplot-ii-creando-y-manejando-ventanas-y-configurando-la-sesion/
            </link>
            <description>
                &lt;p&gt;Esto pretende ser un tutorial del m&amp;#243;dulo pyplot de la librer&amp;#237;a matplotlib. El tutorial lo dividiremos de la siguiente forma (que podr&amp;#225; ir cambiando a medida que vayamos avanzando).&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Primeros pasos&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Creando ventanas, manejando ventanas y configurando la sesi&amp;#243;n.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Configuraci&amp;#243;n del gr&amp;#225;fico.&lt;/li&gt;
&lt;li&gt;Tipos de gr&amp;#225;fico I&lt;/li&gt;
&lt;li&gt;Tipos de gr&amp;#225;fico II&lt;/li&gt;
&lt;li&gt;Tipos de gr&amp;#225;fico III&lt;/li&gt;
&lt;li&gt;&amp;#8230;&lt;/li&gt;
&lt;li&gt;Texto y anotaciones (arrow, annotate, table, text&amp;#8230;)&lt;/li&gt;
&lt;li&gt;&lt;del&gt;Herramientas estad&amp;#237;sticas (acorr, cohere, csd,&amp;#160; psd, specgram, spy, xcorr, &amp;#8230;)&lt;/del&gt;&lt;/li&gt;
&lt;li&gt;&lt;del&gt;Eventos e interactividad (connect, disconnect, ginput, waitforbuttonpress&amp;#8230;)&lt;/del&gt;&lt;/li&gt;
&lt;li&gt;Miscel&amp;#225;nea&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;[Para este tutorial se ha usado python 2.7.1, ipython 0.11, numpy 1.6.1 y matplotlib 1.1.0]&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;En todo momento supondremos que se ha iniciado la sesi&amp;#243;n y se ha hecho&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;

import matplotlib.pyplot as plt

import numpy as np

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Como ya comentamos anteriormente, el m&amp;#243;dulo pyplot de matplotlib se suele usar para hacer pruebas r&amp;#225;pidas desde la l&amp;#237;nea de comandos, programitas cortos o programas donde los gr&amp;#225;ficos ser&amp;#225;n, en general, sencillos.&lt;/p&gt;
&lt;p&gt;Normalmente, cuando iniciamos la sesi&amp;#243;n, esta no est&amp;#225; puesta en modo interactivo. En modo interactivo, cada vez que metemos c&amp;#243;digo nuevo relacionado con el gr&amp;#225;fico o la ventana (recordad, una instancia de &lt;a href=&quot;http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes&quot;&gt;matplotlib.axes.Axes&lt;/a&gt; o de &lt;a href=&quot;http://matplotlib.sourceforge.net/api/figure_api.html#matplotlib.figure.Figure&quot;&gt;matplotlib.figure.Figure&lt;/a&gt;, respectivamente), este se actualizar&amp;#225;. Cuando no estamos en modo interactivo, el gr&amp;#225;fico no se actualiza hasta que llamemos a show() (si no hay una ventana abierta) o draw() (normalmente no lo usar&amp;#233;is para nada) expl&amp;#237;citamente. Veamos como es esto:&lt;/p&gt;
&lt;p&gt;Si acabamos de iniciar sesi&amp;#243;n deber&amp;#237;amos estar en modo no interactivo. Para comprobarlo hacemos lo siguiente:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
plt.isinteractive()
False
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Si el resultado es &lt;em&gt;False&lt;/em&gt; significa que estamos en modo no interactivo. Esto significa que si hacemos lo siguiente:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
plt.plot([1,2,3,4,5])
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;No lanzar&amp;#225; una ventana hasta que lo pidamos expl&amp;#237;citamente mediante:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
plt.show()
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Podemos conmutar a modo interactivo o no usando plt.ion() y plt.ioff(), que lo que hacen es poner el modo interactivo en &amp;#8216;on&amp;#8217; o en &amp;#8216;off&amp;#8217;, respectivamente. Como est&amp;#225; en off (recordad que plt.isinteractive() nos ha dado &lt;em&gt;False&lt;/em&gt;, lo que significa que est&amp;#225; en &amp;#8216;off&amp;#8217;), si ahora&amp;#160; hacemos lo siguiente (cerrad antes cualquier ventana de gr&amp;#225;ficos que teng&amp;#225;is abierta):&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
plt.ion()
plt.plot([1,2,3,4])
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Vemos que directamente se abre una ventana nueva sin necesidad de llamar a plt.show(). Yo suelo usar ipython as&amp;#237; para ir probando cosas y cuando ya acierto con como quiero que me salgan los gr&amp;#225;ficos voy a spyder, donde tengo el programa que est&amp;#233; haciendo, y ya escribo el c&amp;#243;digo que necesito con la interfaz orientada a objetos.&lt;/p&gt;
&lt;p&gt;Jugad un poco con plt.isinteractive(), plt.ion(), plt.ioff(), plt.show() y plt.draw() para estar m&amp;#225;s familiarizados con el funcionamiento.&lt;/p&gt;
&lt;p&gt;Lo siguiente que veremos es plt.hold() y plt.ishold(). plt.hold es un conmutador para decir si queremos que los gr&amp;#225;ficos se sobreescriban, que en el mismo gr&amp;#225;fico tengamos diferentes gr&amp;#225;ficas representadas, o para que el gr&amp;#225;fico se limpie y se dibuje la nueva gr&amp;#225;fica cada vez. Si usamos plt.ishold() nos &amp;#8216;responder&amp;#225;&amp;#8217; &lt;em&gt;True&lt;/em&gt; o &lt;em&gt;False&lt;/em&gt;. Si acab&amp;#225;is de iniciar sesi&amp;#243;n, normalmente estar&amp;#225; en &lt;em&gt;True&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
plt.ishold()
True
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Como est&amp;#225; en &lt;em&gt;True&lt;/em&gt;, si hacemos lo siguiente:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
plt.plot(np.random.rand(10))
plt.plot(np.random.rand(10))
plt.show()
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Obtendremos lo siguiente:&lt;br /&gt;
&lt;a href=&quot;http://pybonacci.files.wordpress.com/2012/05/captura-de-pantalla-de-2012-05-12-164745.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-407&quot; src=&quot;http://pybonacci.files.wordpress.com/2012/05/captura-de-pantalla-de-2012-05-12-164745.png?w=700&quot; title=&quot;plt.ishold&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
Si el modo &amp;#8216;hold&amp;#8217; estuviera en &lt;em&gt;False&lt;/em&gt;, solo se habr&amp;#237;a conservado el &amp;#250;ltimo plot y solo ver&amp;#237;amos una l&amp;#237;nea de las dos (probadlo usando plt.hold() y plt.ishold()).&lt;/p&gt;
&lt;p&gt;Si estamos en modo interactivo (plt.ion()) y queremos borrar todos los gr&amp;#225;ficos (&lt;a href=&quot;http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes&quot;&gt;matplotlib.axes.Axes&lt;/a&gt;), t&amp;#237;tulos, &amp;#8230;, de la ventana (&lt;a href=&quot;http://matplotlib.sourceforge.net/api/figure_api.html#matplotlib.figure.Figure&quot;&gt;matplotlib.figure.Figure&lt;/a&gt;) podemos usar plt.clf() y nos volver&amp;#225; a dejar el &amp;#8216;lienzo&amp;#8217; limpio.&lt;/p&gt;
&lt;p&gt;Si seguimos en modo interactivo (plt.ion()) y queremos cerrar la ventana podemos usar plt.close().&lt;/p&gt;
&lt;p&gt;Imaginaos que ahora quer&amp;#233;is trabajar con varias ventanas de gr&amp;#225;ficos simult&amp;#225;neamente donde en una dibuj&amp;#225;is unos datos y en la otra otro tipo de datos y los quer&amp;#233;is ver simult&amp;#225;neamente. Podemos hacer esto d&amp;#225;ndole nombre (o n&amp;#250;mero) a las ventanas con las que vamos a trabajar. Veamos un ejemplo:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
plt.figure('scatter') # Crea una ventana titulada 'scatter'
plt.figure('plot')    # Crea una ventana titulada 'plot'
a = np.random.rand(100) # Generamos un vector de valores aleatorios
b = np.random.rand(100) # Generamos otro vector de valores aleatorios
plt.figure('scatter') # Le decimos que la ventana activa en la que vamos a dibujar es la ventana 'scatter'
plt.scatter(a,b)  # Dibujamos un scatterplot en la ventana 'scatter'
plt.figure('plot') # Ahora cambiamos a la ventana 'plot'
plt.plot(a,b)
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Y os quedar&amp;#237;a algo como lo siguiente:&lt;br /&gt;
&lt;a href=&quot;http://pybonacci.files.wordpress.com/2012/05/figure-scatter.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;size-medium wp-image-409 alignnone&quot; height=&quot;254&quot; src=&quot;http://pybonacci.files.wordpress.com/2012/05/figure-scatter.png?w=300&amp;amp;h=254&quot; title=&quot;figure-scatter&quot; width=&quot;300&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://pybonacci.files.wordpress.com/2012/05/figure-plot.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot; wp-image-408 alignnone&quot; height=&quot;255&quot; src=&quot;http://pybonacci.files.wordpress.com/2012/05/figure-plot.png?w=305&amp;amp;h=255&quot; title=&quot;figure-plot&quot; width=&quot;305&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Es decir, podemos ir dibujando en varias ventanas a la vez. Pod&amp;#233;is probar a cerrar una de las dos ventanas, limpiar la otra, crear una nueva,&amp;#8230; Haciendo una llamada a plt.figure() tambi&amp;#233;n podemos definir la resoluci&amp;#243;n del gr&amp;#225;fico, el tama&amp;#241;o de la figura,&amp;#8230;&lt;/p&gt;
&lt;p&gt;Pero yo no quiero dibujar los gr&amp;#225;ficos en dos ventanas, yo quiero tener varios gr&amp;#225;ficos en la misma. Perfecto, tambi&amp;#233;n podemos hacer eso sin problemas con la ayuda de plt.subplot(). Con plt.subplot() podemos indicar el n&amp;#250;mero de filas y columnas que corresponder&amp;#225;n a como dividimos la ventana. En el siguiente ejemplo se puede ver dos &amp;#225;reas de gr&amp;#225;fico en la misma ventana:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
plt.ion()  # Nos ponemos en modo interactivo
plt.subplot(1,2,1)  # Dividimos la ventana en una fila y dos columnas y dibujamos el primer gr&amp;#225;fico
plt.plot((1,2,3,4,5))
plt.subplot(1,2,2)  # Dividimos la ventana en una fila y dos columnas y dibujamos el segundo gr&amp;#225;fico
plt.plot((5,4,3,2,1))
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Obteniendo el siguiente gr&amp;#225;fico:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://pybonacci.files.wordpress.com/2012/05/subplot12.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-433&quot; src=&quot;https://pybonacci.files.wordpress.com/2012/05/subplot12.png?w=700&quot; title=&quot;subplot12&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Os dejo como ejercicio ver como pod&amp;#233;is conseguir la siguiente gr&amp;#225;fica (si no sab&amp;#233;is como dejad un comentario) y con ello creo que habr&amp;#233;is entendido perfectamente el uso de plt.subplot():&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://pybonacci.files.wordpress.com/2012/05/subplot22.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-434&quot; src=&quot;https://pybonacci.files.wordpress.com/2012/05/subplot22.png?w=700&quot; title=&quot;subplot22&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Por &amp;#250;ltimo, vamos a ver como configurar la sesi&amp;#243;n para ahorrarnos escribir c&amp;#243;digo de m&amp;#225;s. Por ejemplo, imaginaos que quer&amp;#233;is que todas las l&amp;#237;neas sean m&amp;#225;s gruesas por defecto porque os gustan m&amp;#225;s as&amp;#237;, que quer&amp;#233;is usar otro tipo de fuente sin escribirlo expl&amp;#237;citamente cada vez que hac&amp;#233;is un gr&amp;#225;fico, que los gr&amp;#225;ficos se guarden siempre con una resoluci&amp;#243;n superior a la que viene por defecto,&amp;#8230; Para ello pod&amp;#233;is usar plt.rc(), plt.rcParams, plt.rcdefaults(). En este caso vamos a usar plt.rc(), podr&amp;#233;is encontrar m&amp;#225;s informaci&amp;#243;n sobre como configurar matplotlib &lt;a href=&quot;http://matplotlib.sourceforge.net/users/customizing.html&quot;&gt;en este enlace&lt;/a&gt;. Veamos un ejemplo para ver como funciona todo esto:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
plt.ion()  # Nos ponemos en modo interactivo
plt.figure('valores por defecto')  # Creamos una ventana donde dibujamos el gr&amp;#225;fico con la configuraci&amp;#243;n por defecto
plt.suptitle('Titulo valores por defecto')  # Esto sirve para poner t&amp;#237;tulo dentro de la ventana
plt.plot((1,2,3,4,5), label = 'por defecto')  # Hacemos el plot
plt.legend(loc = 2)  # Colocamos la leyenda en la esquina superior izquierda

plt.rc('lines', linewidth = 2)  # A partir de aqu&amp;#237; todas las l&amp;#237;neas que dibujemos ir&amp;#225;n con ancho doble
plt.rc('font', size = 18)  # A partir de aqu&amp;#237; las fuentes que aparezcan en cualquier gr&amp;#225;fico en la misma sesi&amp;#243;n tendr&amp;#225;n mayor tama&amp;#241;o
plt.figure('valores modificados')  # Creamos una ventana donde dibujamos el gr&amp;#225;fico con la configuraci&amp;#243;n por defecto
plt.suptitle('Titulo valores modificados')  # Esto sirve para poner t&amp;#237;tulo dentro de la ventana
plt.plot((1,2,3,4,5), label = u'linea m&amp;#225;s ancha y letra m&amp;#225;s grande')  # Hacemos el plot
plt.legend(loc = 2)  # Colocamos la leyenda en la esquina superior izquierda
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://pybonacci.files.wordpress.com/2012/05/plot-defecto.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;alignnone size-medium wp-image-426&quot; height=&quot;270&quot; src=&quot;https://pybonacci.files.wordpress.com/2012/05/plot-defecto.png?w=300&amp;amp;h=270&quot; title=&quot;plot-defecto&quot; width=&quot;300&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://pybonacci.files.wordpress.com/2012/05/plot-defectomodificado1.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;alignnone  wp-image-427&quot; height=&quot;270&quot; src=&quot;https://pybonacci.files.wordpress.com/2012/05/plot-defectomodificado1.png?w=323&amp;amp;h=270&quot; title=&quot;plot-defectomodificado&quot; width=&quot;323&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Despu&amp;#233;s de usar plt.rc() para modificar un par&amp;#225;metro esa modificaci&amp;#243;n ser&amp;#225; para toda la sesi&amp;#243;n a no ser que lo volvamos a modificar expl&amp;#237;citamente o a no ser que usemos plt.rcdefaults(), que devolver&amp;#225; todos los par&amp;#225;metros a los valores por defecto.&lt;/p&gt;
&lt;p&gt;Si quieres puedes pasar a la siguiente parte.&lt;/p&gt;
&lt;br /&gt;Filed under: &lt;a href=&quot;http://pybonacci.wordpress.com/category/basico/&quot;&gt;B&amp;#225;sico&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/category/tutoriales/&quot;&gt;Tutoriales&lt;/a&gt;  &lt;a href=&quot;http://feeds.wordpress.com/1.0/gocomments/pybonacci.wordpress.com/262/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/comments/pybonacci.wordpress.com/262/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godelicious/pybonacci.wordpress.com/262/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/delicious/pybonacci.wordpress.com/262/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gofacebook/pybonacci.wordpress.com/262/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/facebook/pybonacci.wordpress.com/262/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gotwitter/pybonacci.wordpress.com/262/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/twitter/pybonacci.wordpress.com/262/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gostumble/pybonacci.wordpress.com/262/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/stumble/pybonacci.wordpress.com/262/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godigg/pybonacci.wordpress.com/262/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/digg/pybonacci.wordpress.com/262/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/goreddit/pybonacci.wordpress.com/262/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/reddit/pybonacci.wordpress.com/262/&quot; /&gt;&lt;/a&gt; &lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://stats.wordpress.com/b.gif?host=pybonacci.wordpress.com&amp;#038;blog=33759577&amp;#038;post=262&amp;#038;subd=pybonacci&amp;#038;ref=&amp;#038;feed=1&quot; width=&quot;1&quot; /&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://python.majibu.org/preguntas/1517/permitir-links-en-los-fields-en-el-admin-con-django
            </guid>
            <title>
                python majibu: Permitir links en los fields en el admin con Django
            </title>
            <pubDate>
                Fri, 18 May 2012 15:24:12 GMT
            </pubDate>
            <link>
                http://python.majibu.org/preguntas/1517/permitir-links-en-los-fields-en-el-admin-con-django
            </link>
            <description>
                &lt;p&gt;Si bien se puede hacer en el admin que el &lt;strong&gt;list_display&lt;/strong&gt; contenga texto formateado a html, ajustando el valor de la propiedad &lt;strong&gt;allow_tags&lt;/strong&gt; a  True.&lt;/p&gt;
&lt;p&gt;&amp;#191;C&amp;#243;mo podr&amp;#237;a hacer lo mismo con un atributo del modelo(&lt;strong&gt;fields&lt;/strong&gt;)? que he ajustado como de solo lectura mediante la tupla &lt;strong&gt;readonly_fields&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Yo intent&amp;#233; hacerlo del mismo modo que para un &lt;strong&gt;list_display&lt;/strong&gt; pero no me funcion&amp;#243;.&lt;/p&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://python.majibu.org/preguntas/1504/deployment-con-django-gunicorn-o-uwsgi
            </guid>
            <title>
                python majibu: Deployment con django: gunicorn o uwsgi?
            </title>
            <pubDate>
                Thu, 17 May 2012 08:51:01 GMT
            </pubDate>
            <link>
                http://python.majibu.org/preguntas/1504/deployment-con-django-gunicorn-o-uwsgi
            </link>
            <description>
                &lt;p&gt;Estoy realizando un deployment de un proyecto de django con un par de instancias manejadas por supervisord, y estaba pregunt&amp;#225;ndome qu&amp;#233; podr&amp;#237;a ser m&amp;#225;s efectivo en cuanto a tiempo de respuesta y gasto de recursos, si gunicorn o uwsgi.&lt;/p&gt;
&lt;p&gt;Ahora mismo estoy con uwsgi, pero el servidor llega a comer hasta 1GB de RAM, auque responde de forma muy r&amp;#225;pida a las peticiones (ver: &lt;a href=&quot;http://188.40.90.250&quot;&gt;http://188.40.90.250&lt;/a&gt;, el deployment est&amp;#225; incompleto, si intentais registraros dar&amp;#225; error).&lt;/p&gt;
&lt;p&gt;Que me recomendar&amp;#237;ais vosotros para el deployment? El combo que estoy usando es supervisord + nginx + uwsgi + django 1.4&lt;/p&gt;
&lt;p&gt;Actaulizaci&amp;#243;n: Tras ejecutar un cat en cada proceso de uwsgi y mirar mediante top y ps los consumos, tengo dos procesos de uwsgi (workers 2, threads 40) que consumen 400MB de ram cada uno, es normal?&lt;/p&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://pybonacci.wordpress.com/?p=204
            </guid>
            <title>
                Pybonacci: Manual de introducci&amp;#243;n a matplotlib.pyplot (I): Primeros pasos.
            </title>
            <pubDate>
                Mon, 14 May 2012 19:31:00 GMT
            </pubDate>
            <link>
                http://pybonacci.wordpress.com/2012/05/14/manual-de-introduccion-a-matplotlib-pyplot-i/
            </link>
            <description>
                &lt;p&gt;Esto pretende ser un tutorial del m&amp;#243;dulo pyplot de la librer&amp;#237;a matplotlib. El tutorial lo dividiremos de la siguiente forma (que podr&amp;#225; ir cambiando a medida que vayamos avanzando).&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Primeros pasos&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Creando ventanas, manejando ventanas y configurando la sesi&amp;#243;n.&lt;/li&gt;
&lt;li&gt;Configuraci&amp;#243;n del gr&amp;#225;fico.&lt;/li&gt;
&lt;li&gt;Tipos de gr&amp;#225;fico I&lt;/li&gt;
&lt;li&gt;Tipos de gr&amp;#225;fico II&lt;/li&gt;
&lt;li&gt;Tipos de gr&amp;#225;fico III&lt;/li&gt;
&lt;li&gt;&amp;#8230;&lt;/li&gt;
&lt;li&gt;Texto y anotaciones (arrow, annotate, table, text&amp;#8230;)&lt;/li&gt;
&lt;li&gt;&lt;del&gt;Herramientas estad&amp;#237;sticas (acorr, cohere, csd,&amp;#160; psd, specgram, spy, xcorr, &amp;#8230;)&lt;/del&gt;&lt;/li&gt;
&lt;li&gt;&lt;del&gt;Eventos e interactividad (connect, disconnect, ginput, waitforbuttonpress&amp;#8230;)&lt;/del&gt;&lt;/li&gt;
&lt;li&gt;Miscel&amp;#225;nea&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;[Para este tutorial se ha usado python 2.7.1, ipython 0.11, numpy 1.6.1 y matplotlib 1.1.0]&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;En todo momento supondremos que se ha iniciado la sesi&amp;#243;n y se ha hecho&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;

import matplotlib.pyplot as plt

import numpy as np

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Para empezar diremos que hay tres formas de usar la librer&amp;#237;a Matplotlib:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;La podemos usar desde&lt;em&gt;&lt;/em&gt; python usando el m&amp;#243;dulo pylab. El m&amp;#243;dulo pylab pretende mostrar un entorno de trabajo parecido al de&lt;a href=&quot;http://guillemborrell.es/blog/carta-abierta-a-mathworks/&quot;&gt; matlab&lt;/a&gt; mezclando las librer&amp;#237;as numpy y matplotlib. Es la forma menos pyth&amp;#243;nica de usar matplotlib y se obtiene usando&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;

from pylab import *

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Normalmente solo se recomienda para hacer pruebas r&amp;#225;pidas desde la l&amp;#237;nea de comandos.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Una segunda forma, que es la que veremos en este tutorial, es usando el m&amp;#243;dulo pyplot.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;

import matplotlib.pyplot as plt

&lt;/pre&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Por &amp;#250;ltimo, la forma m&amp;#225;s recomendable y pyth&amp;#243;nica, pero m&amp;#225;s compleja, ser&amp;#237;a usar matplotlib mediante la interfaz orientada a objetos. Cuando se programa con matplotlib, no mientras se trabaja interactivamente, esta es la forma que permite tener m&amp;#225;s control sobre el c&amp;#243;digo. Quiz&amp;#225; veamos esto en el futuro si alguno nos animamos/os anim&amp;#225;is a escribir sobre ello.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Absolutamente todo lo que vamos a usar en este tutorial y que est&amp;#225; relacionado con matplotlib.pyplot lo podr&amp;#233;is encontrar documentado y detallado &lt;a href=&quot;http://matplotlib.sourceforge.net/api/pyplot_api.html#module-matplotlib.pyplot&quot; title=&quot;Documentaci&amp;#243;n oficial de matplotlib.pyplot (1.1.0)&quot;&gt;aqu&amp;#237;&lt;/a&gt;. Como he comentado, todo lo que vamos a ver est&amp;#225; en el anterior enlace, pero no todo lo que est&amp;#225; en el anterior enlace lo vamos a ver. Por ejemplo, en el &amp;#237;ndice ver&amp;#233;is que he tachado los puntos 9 y 10, las funciones estad&amp;#237;sticas y las funciones que permiten meter algo de interactividad en los gr&amp;#225;ficos dentro de pyplot. Las funciones estad&amp;#237;sticas incluidas son pocas, algunas son complejas y muy espec&amp;#237;ficas y las veo poco coherentes como grupo dentro de pyplot, para ello ya tenemos scipy y estas funciones estar&amp;#237;an mejor ah&amp;#237; para separar lo que es &amp;#8216;gr&amp;#225;ficar&amp;#8217; (&lt;a href=&quot;http://buscon.rae.es/draeI/SrvltGUIBusUsual?TIPO_HTML=2&amp;amp;TIPO_BUS=3&amp;amp;LEMA=graficar&quot;&gt;en espa&amp;#241;ol de Sud&amp;#225;merica existe la palabra&lt;/a&gt;) de lo que es analizar datos. Para interactividad con los gr&amp;#225;ficos tenemos el m&amp;#243;dulo &lt;a href=&quot;http://matplotlib.sourceforge.net/api/widgets_api.html#module-matplotlib.widgets&quot;&gt;matplotlib.widgets&lt;/a&gt;, much&amp;#237;simo m&amp;#225;s completo.&lt;/p&gt;
&lt;p&gt;Para que quede claro desde un principio, las dos zonas principales donde se dibujaran cosas o sobre las que se interactuar&amp;#225; ser&amp;#225;n:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;figure, que es una instancia de &lt;a href=&quot;http://matplotlib.sourceforge.net/api/figure_api.html#matplotlib.figure.Figure&quot;&gt;matplotlib.figure.Figure&lt;/a&gt;. Y es la ventana donde ir&amp;#225; el o los gr&amp;#225;ficos en s&amp;#237;:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href=&quot;https://pybonacci.files.wordpress.com/2012/04/pantallazo-del-2012-04-23-213736.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-255&quot; src=&quot;https://pybonacci.files.wordpress.com/2012/04/pantallazo-del-2012-04-23-213736.png?w=700&quot; title=&quot;Figure&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;axes, que es una instancia de &lt;a href=&quot;http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes&quot;&gt;matplotlib.axes.Axes&lt;/a&gt;, que es el gr&amp;#225;fico en s&amp;#237; donde se dibujar&amp;#225; todo lo que le digamos y est&amp;#225; localizada dentro de una figure.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href=&quot;https://pybonacci.files.wordpress.com/2012/04/pantallazo-del-2012-04-23-213814.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-256&quot; src=&quot;https://pybonacci.files.wordpress.com/2012/04/pantallazo-del-2012-04-23-213814.png?w=700&quot; title=&quot;Axes&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Para lo primero (figure) usaremos la palabra &amp;#8216;ventana&amp;#8217; mientras que para lo segundo (axes) usaremos la palabra &amp;#8216;gr&amp;#225;fico&amp;#8217;.&lt;/p&gt;
&lt;p&gt;Si quieres puedes pasar a la siguiente secci&amp;#243;n (pr&amp;#243;ximamente&amp;#8230;).&lt;/p&gt;
&lt;br /&gt;Filed under: &lt;a href=&quot;http://pybonacci.wordpress.com/category/basico/&quot;&gt;B&amp;#225;sico&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/category/tutoriales/&quot;&gt;Tutoriales&lt;/a&gt;  &lt;a href=&quot;http://feeds.wordpress.com/1.0/gocomments/pybonacci.wordpress.com/204/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/comments/pybonacci.wordpress.com/204/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godelicious/pybonacci.wordpress.com/204/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/delicious/pybonacci.wordpress.com/204/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gofacebook/pybonacci.wordpress.com/204/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/facebook/pybonacci.wordpress.com/204/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gotwitter/pybonacci.wordpress.com/204/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/twitter/pybonacci.wordpress.com/204/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gostumble/pybonacci.wordpress.com/204/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/stumble/pybonacci.wordpress.com/204/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godigg/pybonacci.wordpress.com/204/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/digg/pybonacci.wordpress.com/204/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/goreddit/pybonacci.wordpress.com/204/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/reddit/pybonacci.wordpress.com/204/&quot; /&gt;&lt;/a&gt; &lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://stats.wordpress.com/b.gif?host=pybonacci.wordpress.com&amp;#038;blog=33759577&amp;#038;post=204&amp;#038;subd=pybonacci&amp;#038;ref=&amp;#038;feed=1&quot; width=&quot;1&quot; /&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://javaguirre.net/?p=960
            </guid>
            <title>
                JavAguirre.net: Raequel, scraping en la web de la rae con app engine
            </title>
            <pubDate>
                Mon, 14 May 2012 13:50:48 GMT
            </pubDate>
            <link>
                http://javaguirre.net/2012/05/14/raequel-scraping-en-la-web-de-la-rae-con-app-engine/
            </link>
            <description>
                &lt;p&gt;La semana pasada me enter&amp;#233; de que &lt;a href=&quot;http://duckduckgo.com&quot;&gt;DuckDuckGo&lt;/a&gt; te permit&amp;#237;a implementar plugins que luego ellos testean e introducen en la plataforma (&lt;a href=&quot;http://duckduckhack.com/&quot;&gt;DuckDuckHack&lt;/a&gt;), me pareci&amp;#243; que pod&amp;#237;a ser muy divertido. :-)&lt;/p&gt;
&lt;p&gt;Tras pensar varias cosas y ver c&amp;#243;mo se pod&amp;#237;a implementar el plugin, estuve investigando por ah&amp;#237; y me pareci&amp;#243; buena idea hacer un plugin que buscase en la RAE la palabra buscada y devolviese las acepciones de &amp;#233;sta.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;En Github encontr&amp;#233; a una persona que hab&amp;#237;a hecho scraping sobre la web de la RAE&lt;/strong&gt; y con el &lt;a href=&quot;https://developers.google.com/appengine/downloads?hl=es#Google_App_Engine_SDK_for_Python&quot;&gt;SDK de Python para Google App Engine&lt;/a&gt; hab&amp;#237;a creado una API, este fue mi punto de partida. :-)&lt;/p&gt;
&lt;p&gt;Leyendo el c&amp;#243;digo y prob&amp;#225;ndolo me di cuenta de que necesitaba por el momento un par de cosas por implementar, una era que &lt;em&gt;la API deb&amp;#237;a ser JSONP&lt;/em&gt;, y otra que las peticiones deb&amp;#237;an responder m&amp;#225;s r&amp;#225;pido.&lt;/p&gt;
&lt;p&gt;La primera soluci&amp;#243;n fue muy sencilla, simplemente a&amp;#241;adir un par de cabeceras:&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;python&quot; style=&quot;font-family: monospace;&quot;&gt;&lt;span style=&quot;color: #008000;&quot;&gt;self&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;response&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;headers&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;'Access-Control-Allow-Origin'&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt; = &lt;span style=&quot;color: #483d8b;&quot;&gt;'*'&lt;/span&gt;
&lt;span style=&quot;color: #008000;&quot;&gt;self&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;response&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;headers&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;'Access-Control-Allow-Methods'&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt; = &lt;span style=&quot;color: #483d8b;&quot;&gt;'GET'&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;La segunda tambi&amp;#233;n result&amp;#243; muy sencilla, ya que el &lt;em&gt;SDK de Google App Engine&lt;/em&gt; dispone de una biblioteca para &lt;strong&gt;memcache&lt;/strong&gt;, bast&amp;#243; a&amp;#241;adir esa funcionalidad a la petici&amp;#243;n JSON/JSONP y listo.&lt;/p&gt;
&lt;p&gt;Ahora toca la parte de DuckDuckGo, har&amp;#225; falta tiempo para ello, &lt;a href=&quot;https://github.com/tian2992/raequel&quot;&gt;el proyecto est&amp;#225; en Github&lt;/a&gt;.&lt;/p&gt;
&lt;h2 class=&quot;related_post_title&quot;&gt;Related Posts&lt;/h2&gt;&lt;ul class=&quot;related_post&quot;&gt;&lt;li&gt;May 10, 2012 -- &lt;a href=&quot;http://javaguirre.net/2012/05/10/using-aspen/&quot; title=&quot;Using Aspen&quot;&gt;Using Aspen&lt;/a&gt; (0)&lt;/li&gt;&lt;li&gt;April 19, 2012 -- &lt;a href=&quot;http://javaguirre.net/2012/04/19/m2crypto-from-pip-in-old-gnulinux-os/&quot; title=&quot;M2Crypto from pip in old GNU/Linux OS&quot;&gt;M2Crypto from pip in old GNU/Linux OS&lt;/a&gt; (0)&lt;/li&gt;&lt;li&gt;April 1, 2012 -- &lt;a href=&quot;http://javaguirre.net/2012/04/01/ducksboard-python-module/&quot; title=&quot;Ducksboard Python module&quot;&gt;Ducksboard Python module&lt;/a&gt; (0)&lt;/li&gt;&lt;/ul&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://python.majibu.org/preguntas/1500/django-pyjamas-vs-pythonwebkit
            </guid>
            <title>
                python majibu: Django: Pyjamas vs pythonwebkit?
            </title>
            <pubDate>
                Sun, 13 May 2012 03:30:56 GMT
            </pubDate>
            <link>
                http://python.majibu.org/preguntas/1500/django-pyjamas-vs-pythonwebkit
            </link>
            <description>
                &lt;p&gt;Hola! :D&lt;/p&gt;
&lt;p&gt;otra duda que me surge sin haber escrito ni una sola linea de c&amp;#243;digo :).
Sucede que en el desarrollo web, usar javascript es la regla, si deseas que tu sitio sea &quot;din&amp;#225;mico&quot; (&amp;#191;usas flash para esta labor? disculpe &amp;#191;De que planeta viene usted?).&lt;/p&gt;
&lt;p&gt;En una b&amp;#250;squeda, encontr&amp;#233; dos posibilidades para usar Javascript sin usar Javascript, una es &lt;strong&gt;Pyjamas&lt;/strong&gt; y la otra es &lt;strong&gt;pythonwebkit&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Pyjamas parece ser algo as&amp;#237; como Django... creo. Y embeber Pyjamas en Django es una suerte de usar un middleware escrito en Python para hacerlo funcionar. &amp;#191;Pero Pytonwebkit?&lt;/p&gt;
&lt;p&gt;Por eso recurro a ustedes que tienen m&amp;#225;s experiencia en desarrollo web, quiero escuchar sus opiniones sobre &lt;a href=&quot;http://pyjs.org/&quot;&gt;Pyjamas&lt;/a&gt; vs &lt;a href=&quot;http://www.gnu.org/software/pythonwebkit/&quot;&gt;PythonWebKit&lt;/a&gt; (para usar dentro y fuera de Django) como reemplazos a Javascript para la web.&lt;/p&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://alvarezalonso.es/monobotblog/?p=991
            </guid>
            <title>
                Monobot: [python] manejo de directorios y ficheros
            </title>
            <pubDate>
                Sat, 12 May 2012 18:00:14 GMT
            </pubDate>
            <link>
                http://alvarezalonso.es/monobotblog/?p=991
            </link>
            <description>
                &lt;p&gt;Esta es la tipica pagina de referencia cuando quiero mirar referencias al manejo de &lt;a href=&quot;http://code.google.com/p/asi-iesenlaces/wiki/ArchivosyDirectoriosConPython&quot; target=&quot;_blank&quot;&gt;directorios y ficheros&lt;/a&gt; &amp;#8230; la tengo como favoritos y la miro cada varios dias &amp;#8230; la quer&amp;#237;a compartir con ustedes.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://python.majibu.org/preguntas/1493/subir-ficheros-en-django
            </guid>
            <title>
                python majibu: Subir ficheros en django
            </title>
            <pubDate>
                Sat, 12 May 2012 11:58:15 GMT
            </pubDate>
            <link>
                http://python.majibu.org/preguntas/1493/subir-ficheros-en-django
            </link>
            <description>
                &lt;p&gt;problema con subir archivos en django:&lt;/p&gt;
&lt;p&gt;en MODELS&lt;/p&gt;
&lt;table class=&quot;codehilitetable&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;linenos&quot;&gt;&lt;div class=&quot;linenodiv&quot;&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Usuario_curriculo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;nombreusuario&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CharField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;nombre&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CharField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;apellidos&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CharField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;dni&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CharField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;blank&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;foto_carnet&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FileField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;upload_to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;settings&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MEDIA_ROOT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;__unicode__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'USUARIO:&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; | NOMBRE:&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; | EMAIL:&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
                    &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;nombreusuario&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;nombre&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;apellidos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                    &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;email&lt;/span&gt;
                    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;__unicode__&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;allow_tags&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;en FORMS:&lt;/p&gt;
&lt;table class=&quot;codehilitetable&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;linenos&quot;&gt;&lt;div class=&quot;linenodiv&quot;&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;FormularioPersonal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ModelForm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;foto_carnet&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;forms&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FileField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;nombreusuario&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;forms&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CharField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Nombre de usuario'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;widget&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;forms&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HiddenInput&lt;/span&gt;
                &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;nombre&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;forms&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CharField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Nombre*'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;apellidos&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;forms&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CharField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Apellidos*'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;dni&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ESIdentityCardNumberField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;en VISTAS&lt;/p&gt;
&lt;table class=&quot;codehilitetable&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;linenos&quot;&gt;&lt;div class=&quot;linenodiv&quot;&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;c_datos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sd&quot;&gt;'''donde definimos los datos personales y de contacto'''&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;_nombreusuario&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;_persona&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;get_object_or_404&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Usuario_curriculo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;nombreusuario&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_nombreusuario&lt;/span&gt;
                    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Http404&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;_persona&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;method&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'POST'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;form&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;forms&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FormularioPersonal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;POST&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FILES&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;instance&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_persona&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;form&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_valid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;form&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;save&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HttpResponseRedirect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reverse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'formacion'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;form&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;forms&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FormularioPersonal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;instance&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_persona&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;render_to_response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;s&quot;&gt;'vista_formulario.html'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'titulo'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'DATOS PERSONALES'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;s&quot;&gt;'form'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;form&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context_instance&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;RequestContext&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;el problema es que request.FILES esta vacio ... es un diccionario sin ninguna entrada y por tanto no se graba ni hace nada .. de hecho si el formulario no pongo required=False aunque si que se haya seleccionado me canta el error.&lt;/p&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://javaguirre.net/?p=950
            </guid>
            <title>
                JavAguirre.net: Using Aspen
            </title>
            <pubDate>
                Thu, 10 May 2012 21:48:22 GMT
            </pubDate>
            <link>
                http://javaguirre.net/2012/05/10/using-aspen/
            </link>
            <description>
                &lt;p&gt;&lt;a href=&quot;http://aspen.io/&quot;&gt;Aspen is a python web framework based in the filesystem&lt;/a&gt;, mixing controller and view in the same archive, it&amp;#8217;s called a &lt;em&gt;Simplate&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;We had some static html files in production, but months later we needed to add some server logic to this ones, &lt;strong&gt;without changing any url and having it integrated fast in our actual environment&lt;/strong&gt;. These conditions make us think in this framework, it is perfect for this kind of situation, we hadn&amp;#8217;t to change our actual filesystem for our html files and we could have easily integrated this new logic inside them. :-)&lt;/p&gt;
&lt;p&gt;Our main problem using aspen is the lack of documentation, in my opinion is really poor and it could explain more and better basic things, such as requests handling. Anyway, I like to explore the code but sometimes you don&amp;#8217;t want to spend some time in it when you have to get things done.&lt;/p&gt;
&lt;p&gt;I have been using &lt;strong&gt;Django&lt;/strong&gt; and &lt;strong&gt;Flask&lt;/strong&gt; and I could say I found basics less intuitive in aspen than the others. I will try to explain what I meant in a later post when I get deeper in it.&lt;/p&gt;
&lt;h2 class=&quot;related_post_title&quot;&gt;Related Posts&lt;/h2&gt;&lt;ul class=&quot;related_post&quot;&gt;&lt;li&gt;April 1, 2012 -- &lt;a href=&quot;http://javaguirre.net/2012/04/01/mejoras-en-openboe/&quot; title=&quot;Mejoras en Openboe&quot;&gt;Mejoras en Openboe&lt;/a&gt; (0)&lt;/li&gt;&lt;li&gt;January 10, 2012 -- &lt;a href=&quot;http://javaguirre.net/2012/01/10/anadido-el-boe-diario-y-el-borme-a-openboe/&quot; title=&quot;A&amp;#241;adido el BOE diario y el Borme a Openboe&quot;&gt;A&amp;#241;adido el BOE diario y el Borme a Openboe&lt;/a&gt; (0)&lt;/li&gt;&lt;li&gt;January 8, 2012 -- &lt;a href=&quot;http://javaguirre.net/2012/01/08/avance-en-openboe-estilos-y-busqueda-por-fecha/&quot; title=&quot;Avance en Openboe, estilos y b&amp;#250;squeda por fecha&quot;&gt;Avance en Openboe, estilos y b&amp;#250;squeda por fecha&lt;/a&gt; (0)&lt;/li&gt;&lt;/ul&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://pybonacci.wordpress.com/?p=385
            </guid>
            <title>
                Pybonacci: C&amp;#243;mo crear una matriz tridiagonal en Python con NumPy y SciPy
            </title>
            <pubDate>
                Thu, 10 May 2012 09:41:37 GMT
            </pubDate>
            <link>
                http://pybonacci.wordpress.com/2012/05/10/como-crear-una-matriz-tridiagonal-en-python-con-numpy-y-scipy/
            </link>
            <description>
                &lt;h2&gt;Introducci&amp;#243;n&lt;/h2&gt;
&lt;p&gt;En este r&amp;#225;pido apunte vamos a ver c&amp;#243;mo construir una &lt;a href=&quot;http://en.wikipedia.org/wiki/Tridiagonal_matrix&quot;&gt;matriz tridiagonal&lt;/a&gt; en Python utilizando NumPy y SciPy. Una &lt;strong&gt;matriz tridiagonal&lt;/strong&gt; es una matriz &lt;em&gt;cuadrada&amp;#160;&lt;/em&gt;que solamente tiene elementos distintos de cero en su diagonal principal y en las dos diagonales adyacentes a esta (la superdiagonal y la subdiagonal). Las matrices tridiagonales aparecen mucho en c&amp;#225;lculo num&amp;#233;rico, por ejemplo en la discretizaci&amp;#243;n de ecuaciones diferenciales, y tienen la caracter&amp;#237;stica de ser&amp;#160;&lt;strong&gt;matrices dispersas&lt;/strong&gt; (en lugar de&amp;#160;&lt;em&gt;densas&lt;/em&gt;) al ser la mayor&amp;#237;a de sus elementos cero.&lt;/p&gt;
&lt;p&gt;Sin que sirva de precedente, hoy vamos a escribir c&amp;#243;digo que sea compatible tanto con Python 2 como con Python 3. Es un cambio nimio, pero merece la pena ir acostumbr&amp;#225;ndose a pensar que tarde o temprano habr&amp;#225; que abandonar Python 2 &lt;img alt=&quot;:)&quot; class=&quot;wp-smiley&quot; src=&quot;http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif&quot; /&gt; &lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;En esta entrada se ha usado python 2.7.3, numpy 1.6.1 y scipy 0.10.1 &lt;/strong&gt;&lt;/em&gt;&lt;strong&gt;y es compatible con&amp;#160;&lt;/strong&gt;&lt;strong&gt;python 3.2.3&lt;/strong&gt;&lt;em&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;span id=&quot;more-385&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;Problema matem&amp;#225;tico&lt;/h2&gt;
&lt;p&gt;Como ejemplo, vamos a construir la matriz del sistema de ecuaciones diferenciales ordinarias que resulta de discretizar la ecuaci&amp;#243;n del calor unidimensional&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;{&amp;#92;displaystyle &amp;#92;frac{&amp;#92;partial u}{&amp;#92;partial t} = &amp;#92;mathcal{L}(u) = &amp;#92;frac{&amp;#92;partial^2 u}{&amp;#92;partial x^2}}&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%7B%5Cdisplaystyle+%5Cfrac%7B%5Cpartial+u%7D%7B%5Cpartial+t%7D+%3D+%5Cmathcal%7BL%7D%28u%29+%3D+%5Cfrac%7B%5Cpartial%5E2+u%7D%7B%5Cpartial+x%5E2%7D%7D&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;{&amp;#92;displaystyle &amp;#92;frac{&amp;#92;partial u}{&amp;#92;partial t} = &amp;#92;mathcal{L}(u) = &amp;#92;frac{&amp;#92;partial^2 u}{&amp;#92;partial x^2}}&quot; /&gt;&lt;/p&gt;
&lt;p&gt;en el dominio &lt;img alt=&quot;x &amp;#92;in [0, 1]&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=x+%5Cin+%5B0%2C+1%5D&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;x &amp;#92;in [0, 1]&quot; /&gt;. Aproximando el operador &lt;img alt=&quot;&amp;#92;mathcal{L}&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%5Cmathcal%7BL%7D&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;&amp;#92;mathcal{L}&quot; /&gt; mediante &lt;a href=&quot;http://es.wikipedia.org/wiki/Diferencia_finita&quot;&gt;diferencias centradas&lt;/a&gt;&amp;#160;de orden 2 en los puntos de colocaci&amp;#243;n &lt;img alt=&quot;x_0,&amp;#92;, x_1,&amp;#92;, &amp;#92;dots,&amp;#92;, x_N&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=x_0%2C%5C%2C+x_1%2C%5C%2C+%5Cdots%2C%5C%2C+x_N&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;x_0,&amp;#92;, x_1,&amp;#92;, &amp;#92;dots,&amp;#92;, x_N&quot; /&gt;, se obtiene para los puntos interiores&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;{&amp;#92;displaystyle &amp;#92;frac{d u_j}{d t} = &amp;#92;frac{1}{&amp;#92;Delta x^2} (u_{j + 1} - 2 u_j + u_{j - 1})}&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%7B%5Cdisplaystyle+%5Cfrac%7Bd+u_j%7D%7Bd+t%7D+%3D+%5Cfrac%7B1%7D%7B%5CDelta+x%5E2%7D+%28u_%7Bj+%2B+1%7D+-+2+u_j+%2B+u_%7Bj+-+1%7D%29%7D&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;{&amp;#92;displaystyle &amp;#92;frac{d u_j}{d t} = &amp;#92;frac{1}{&amp;#92;Delta x^2} (u_{j + 1} - 2 u_j + u_{j - 1})}&quot; /&gt;&lt;/p&gt;
&lt;p&gt;que, expresado matricialmente, queda&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;{&amp;#92;displaystyle &amp;#92;frac{d U}{d t} = A U + b}&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%7B%5Cdisplaystyle+%5Cfrac%7Bd+U%7D%7Bd+t%7D+%3D+A+U+%2B+b%7D&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;{&amp;#92;displaystyle &amp;#92;frac{d U}{d t} = A U + b}&quot; /&gt;&lt;/p&gt;
&lt;p&gt;con&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;U = &amp;#92;begin{pmatrix} u_1 &amp;#92;&amp;#92; u_2 &amp;#92;&amp;#92; &amp;#92;vdots &amp;#92;&amp;#92; u_{N - 1} &amp;#92;end{pmatrix}&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=U+%3D+%5Cbegin%7Bpmatrix%7D+u_1+%5C%5C+u_2+%5C%5C+%5Cvdots+%5C%5C+u_%7BN+-+1%7D+%5Cend%7Bpmatrix%7D&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;U = &amp;#92;begin{pmatrix} u_1 &amp;#92;&amp;#92; u_2 &amp;#92;&amp;#92; &amp;#92;vdots &amp;#92;&amp;#92; u_{N - 1} &amp;#92;end{pmatrix}&quot; /&gt;&lt;/p&gt;
&lt;p&gt;y&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;A = &amp;#92;begin{pmatrix}  -2 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 &amp;amp; &amp;#92;dots &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 &amp;#92;&amp;#92;  1 &amp;amp; -2 &amp;amp; 1 &amp;amp; 0 &amp;amp; &amp;#92;dots &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 &amp;#92;&amp;#92;  0 &amp;amp; 1 &amp;amp; -2 &amp;amp; 1 &amp;amp; &amp;#92;dots &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 &amp;#92;&amp;#92;  &amp;#92;vdots &amp;amp; &amp;#92;vdots &amp;amp; &amp;#92;vdots &amp;amp; &amp;#92;vdots &amp;amp; &amp;#92;ddots &amp;amp; &amp;#92;vdots &amp;amp; &amp;#92;vdots &amp;amp; &amp;#92;vdots &amp;#92;&amp;#92;  0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; &amp;#92;dots &amp;amp; 0 &amp;amp; 1 &amp;amp; -2  &amp;#92;end{pmatrix}    &quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=A+%3D+%5Cbegin%7Bpmatrix%7D++-2+%26+1+%26+0+%26+0+%26+%5Cdots+%26+0+%26+0+%26+0+%5C%5C++1+%26+-2+%26+1+%26+0+%26+%5Cdots+%26+0+%26+0+%26+0+%5C%5C++0+%26+1+%26+-2+%26+1+%26+%5Cdots+%26+0+%26+0+%26+0+%5C%5C++%5Cvdots+%26+%5Cvdots+%26+%5Cvdots+%26+%5Cvdots+%26+%5Cddots+%26+%5Cvdots+%26+%5Cvdots+%26+%5Cvdots+%5C%5C++0+%26+0+%26+0+%26+0+%26+%5Cdots+%26+0+%26+1+%26+-2++%5Cend%7Bpmatrix%7D++++&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;A = &amp;#92;begin{pmatrix}  -2 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 &amp;amp; &amp;#92;dots &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 &amp;#92;&amp;#92;  1 &amp;amp; -2 &amp;amp; 1 &amp;amp; 0 &amp;amp; &amp;#92;dots &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 &amp;#92;&amp;#92;  0 &amp;amp; 1 &amp;amp; -2 &amp;amp; 1 &amp;amp; &amp;#92;dots &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 &amp;#92;&amp;#92;  &amp;#92;vdots &amp;amp; &amp;#92;vdots &amp;amp; &amp;#92;vdots &amp;amp; &amp;#92;vdots &amp;amp; &amp;#92;ddots &amp;amp; &amp;#92;vdots &amp;amp; &amp;#92;vdots &amp;amp; &amp;#92;vdots &amp;#92;&amp;#92;  0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; &amp;#92;dots &amp;amp; 0 &amp;amp; 1 &amp;amp; -2  &amp;#92;end{pmatrix}    &quot; /&gt;&lt;/p&gt;
&lt;p&gt;Esta matriz es la que vamos a construir.&lt;/p&gt;
&lt;h2&gt;Matriz tridiagonal&lt;/h2&gt;
&lt;p&gt;Para crear la matriz tridiagonal, vamos a utilizar la funci&amp;#243;n &lt;a href=&quot;http://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.spdiags.html#scipy.sparse.spdiags&quot;&gt;&lt;code&gt;spdiags&lt;/code&gt;&lt;/a&gt; del &lt;a href=&quot;http://docs.scipy.org/doc/scipy/reference/sparse.html&quot;&gt;m&amp;#243;dulo &lt;code&gt;sparse&lt;/code&gt; de SciPy&lt;/a&gt;, que contiene diversas funciones para trabajar con matrices dispersas. Los argumentos de esta funci&amp;#243;n son una lista de las diagonales de la matriz y una lista de posiciones donde colocar cada una de esas diagonales. En este caso nos interesan las posiciones &lt;code&gt;k = 0&lt;/code&gt; (diagonal principal), &lt;code&gt;k = 1&lt;/code&gt; (superdiagonal) y &lt;code&gt;k = -1&lt;/code&gt; (subdiagonal).&lt;/p&gt;
&lt;p&gt;Para escribir &lt;strong&gt;c&amp;#243;digo compatible con Python 3&lt;/strong&gt;, al principio del programa escribiremos la l&amp;#237;nea&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
from __future__ import print_function
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;que sustituye la sentencia &lt;code&gt;print&lt;/code&gt; de Python 2 por la nueva &lt;strong&gt;funci&amp;#243;n&lt;/strong&gt; &lt;code&gt;print&lt;/code&gt; de Python 3. El &lt;a href=&quot;http://www.python.org/dev/peps/pep-0236/&quot;&gt;m&amp;#243;dulo &lt;code&gt;__future__&lt;/code&gt;&lt;/a&gt; de Python 2 contiene  varias sentencias que importan caracter&amp;#237;sticas de versiones de Python posteriores, de tal manera que podemos aprovechar nuevas posibilidades o simplemente hacer nuestro c&amp;#243;digo m&amp;#225;s portable. Para lo que vamos a hacer hoy no necesitamos m&amp;#225;s.&lt;/p&gt;
&lt;p&gt;En primer lugar construimos las tres diagonales, haciendo uso de la funci&amp;#243;n &lt;a href=&quot;http://docs.scipy.org/doc/numpy/reference/generated/numpy.ones.html#numpy.ones&quot;&gt;&lt;code&gt;ones&lt;/code&gt;&lt;/a&gt; de NumPy que nos da un array lleno de unos, y utilizando la funci&amp;#243;n &lt;a href=&quot;http://docs.scipy.org/doc/numpy/reference/generated/numpy.vstack.html#numpy.vstack&quot;&gt;&lt;code&gt;vstack&lt;/code&gt;&lt;/a&gt; de Numpy las apilamos (de ah&amp;#237; el nombre) por filas:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
# N&amp;#250;mero de puntos de colocaci&amp;#243;n
N = 100

dl = np.ones(N - 1)
du = np.ones(N - 1)
d0 = -2 * np.ones(N - 1)
d = np.vstack((dl, d0, du))
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Ahora simplemente tenemos que llamar a la funci&amp;#243;n &lt;code&gt;spdiags&lt;/code&gt; para construir la matriz:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
A = sparse.spdiags(d, (-1, 0, 1), N - 1, N - 1)
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;El c&amp;#243;digo quedar&amp;#225; finalmente de esta manera:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
# coding: utf-8
#
# Crea una matriz tridiagonal
# Juan Luis Cano Rodr&amp;#237;guez &amp;lt;juanlu001@gmail.com&amp;gt;

from __future__ import print_function

import numpy as np
from scipy import sparse

# N&amp;#250;mero de puntos de colocaci&amp;#243;n
N = 100

dl = du = np.ones(N - 1)
d0 = -2 * np.ones(N - 1)
d = np.vstack((dl, d0, du))

A = sparse.spdiags(d, (-1, 0, 1), N - 1, N - 1)
print(A.todense())
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Si lo ejecutamos desde IPython:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [1]: %run tridiag.py
[[-2.  1.  0. ...,  0.  0.  0.]
 [ 1. -2.  1. ...,  0.  0.  0.]
 [ 0.  1. -2. ...,  0.  0.  0.]
 ..., 
 [ 0.  0.  0. ..., -2.  1.  0.]
 [ 0.  0.  0. ...,  1. -2.  1.]
 [ 0.  0.  0. ...,  0.  1. -2.]]

In [2]: A
Out[2]: 
&amp;lt;99x99 sparse matrix of type '&amp;lt;class 'numpy.float64'&amp;gt;'
	with 295 stored elements (3 diagonals) in DIAgonal format&amp;gt;

In [3]: type(A)
Out[3]: scipy.sparse.dia.dia_matrix

In [4]: sparse.dia?
Type:       module
Base Class: &amp;lt;class 'module'&amp;gt;
String Form:&amp;lt;module 'scipy.sparse.dia' from '/usr/lib/python3.2/site-packages/scipy/sparse/dia.py'&amp;gt;
Namespace:  Interactive
File:       /usr/lib/python3.2/site-packages/scipy/sparse/dia.py
Docstring:  Sparse DIAgonal format
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;#161;Y ya est&amp;#225;! &lt;img alt=&quot;:)&quot; class=&quot;wp-smiley&quot; src=&quot;http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif&quot; /&gt;  Espero que te haya resultado &amp;#250;til, no dudes mandarnos tus dudas y sugerencias as&amp;#237; como de difundir el art&amp;#237;culo.&lt;/p&gt;
&lt;p&gt;&amp;#161;Un saludo!&lt;/p&gt;
&lt;br /&gt;Filed under: &lt;a href=&quot;http://pybonacci.wordpress.com/category/basico/&quot;&gt;B&amp;#225;sico&lt;/a&gt; Tagged: &lt;a href=&quot;http://pybonacci.wordpress.com/tag/ecuaciones-diferenciales/&quot;&gt;ecuaciones diferenciales&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/edos/&quot;&gt;EDOs&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/edps/&quot;&gt;EDPs&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/matrices/&quot;&gt;matrices&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/numpy/&quot;&gt;numpy&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/python/&quot;&gt;python&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/scipy/&quot;&gt;scipy&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/scipy-sparse/&quot;&gt;scipy.sparse&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gocomments/pybonacci.wordpress.com/385/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/comments/pybonacci.wordpress.com/385/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godelicious/pybonacci.wordpress.com/385/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/delicious/pybonacci.wordpress.com/385/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gofacebook/pybonacci.wordpress.com/385/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/facebook/pybonacci.wordpress.com/385/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gotwitter/pybonacci.wordpress.com/385/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/twitter/pybonacci.wordpress.com/385/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gostumble/pybonacci.wordpress.com/385/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/stumble/pybonacci.wordpress.com/385/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godigg/pybonacci.wordpress.com/385/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/digg/pybonacci.wordpress.com/385/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/goreddit/pybonacci.wordpress.com/385/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/reddit/pybonacci.wordpress.com/385/&quot; /&gt;&lt;/a&gt; &lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://stats.wordpress.com/b.gif?host=pybonacci.wordpress.com&amp;#038;blog=33759577&amp;#038;post=385&amp;#038;subd=pybonacci&amp;#038;ref=&amp;#038;feed=1&quot; width=&quot;1&quot; /&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://www.genbetadev.com/python/cazadores-de-mitos-las-propiedades-privadas-en-python
            </guid>
            <title>
                Genbeta:dev: Cazadores de Mitos: Las propiedades privadas en Python
            </title>
            <pubDate>
                Thu, 10 May 2012 04:00:00 GMT
            </pubDate>
            <link>
                http://www.genbetadev.com/python/cazadores-de-mitos-las-propiedades-privadas-en-python
            </link>
            <description>
                &lt;p&gt;&lt;img alt=&quot;Cazadores de Mitos: Python&quot; class=&quot;centro&quot; src=&quot;http://img.genbetadev.com/galleries/mitos-python/Python.jpg&quot; /&gt;&lt;/p&gt;

	&lt;p&gt;El otro d&amp;#237;a discut&amp;#237;a con un buen amigo en Twitter sobre lo que el llamaba &amp;#8220;&lt;em&gt;falta de private protected y public keywords&lt;/em&gt;&amp;#8220; en Python y record&amp;#233; la tremenda confusi&amp;#243;n y desinformaci&amp;#243;n que hay en la red en relaci&amp;#243;n a las propiedades y/o m&amp;#233;todos &amp;#8220;&lt;em&gt;privadas/os&lt;/em&gt;&amp;#8220; en el lenguaje creado por &lt;strong&gt;Guido Van Rossum&lt;/strong&gt;.&lt;/p&gt;

	&lt;p&gt;En esta entrada voy a intentar explicar &lt;strong&gt;por qu&amp;#233; no existen propiedades ni m&amp;#233;todos privados en Python&lt;/strong&gt; y por qu&amp;#233; no son necesarios, por qu&amp;#233; existe esta confusi&amp;#243;n sobre los m&amp;#233;todos y propiedades (o atributos) que utilizan el underscore (_ y __) y cual es la aut&amp;#233;ntica naturaleza de los mismos.&lt;!--more--&gt;&lt;/p&gt;

	&lt;p&gt;&lt;h2&gt;El origen del Mito&lt;/h2&gt;&lt;br /&gt;

Muy posiblemente el origen del mito comenz&amp;#243; con el &lt;strong&gt;fant&amp;#225;stico libro de Mark Pilgrim&lt;/strong&gt; &lt;a href=&quot;http://www.diveintopython.net/toc/index.html&quot;&gt;Dive into Python&lt;/a&gt; que ha sido el primer contacto y libro de referencia por antonomasia para los novicios en Python desde pr&amp;#225;cticamente su lanzamiento el treinta de octubre del 2000. Yo mismo aprend&amp;#237; con &amp;#233;l.&lt;/p&gt;

	&lt;p&gt;El cap&amp;#237;tulo 5.9. del citado libro, lamentablemente, se titula &amp;#8220;&lt;em&gt;Private Functions&lt;/em&gt;&amp;#8220; y en &amp;#233;l se dice lo siguiente:&lt;br /&gt;

&lt;blockquote&gt;Como en muchos otros lenguajes, Python tiene el concepto de elementos privados:&lt;ul&gt;&lt;li&gt;Funciones privadas, que no pueden ser invocadas desde fuera de su m&amp;#243;dulo&lt;/li&gt;&lt;li&gt;M&amp;#233;todos de clase privados, que no pueden ser invocados desde fuera de su clase&lt;/li&gt;&lt;li&gt;Atributos privados, que no pueden ser accedidos desde fuera de su clase&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;

Pero a diferencia de la mayor&amp;#237;a de lenguajes, lo que hace a una funci&amp;#243;n, m&amp;#233;todo o atributo de Python privado viene determinado enteramente por su nombre.&lt;/p&gt;

	&lt;p&gt;Si el nombre de una funci&amp;#243;n, el m&amp;#233;todo de una clase o uno de sus atributos comienza con (pero no termina con) dos guiones bajos (&lt;em&gt;underscores&lt;/em&gt;), es privado; todo lo dem&amp;#225;s es p&amp;#250;blico.&lt;/blockquote&gt;&lt;/p&gt;

	&lt;p&gt;Para &lt;strong&gt;reforzar esta afirmaci&amp;#243;n&lt;/strong&gt; recurre a un sencillo ejemplo que demuestra que no se puede invocar un m&amp;#233;todo llamado &amp;#8220;&lt;em&gt;__parse&lt;/em&gt;&amp;#8220; desde fuera de una clase. Yo voy a escribir otro sencillo ejemplo &lt;strong&gt;en el &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;REPL&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt; e ir&amp;#233; explicando sobre la marcha por qu&amp;#233; Mark Pilgrim estaba, sencillamente, &lt;strong&gt;equivocado con respecto a este particular&lt;/strong&gt; en espec&amp;#237;fico.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-python&quot;&gt;&amp;gt;&amp;gt; class Gato(object):
&amp;gt;&amp;gt;&amp;gt;    &amp;quot;&amp;quot;&amp;quot;Clase Gato&amp;quot;&amp;quot;&amp;quot;
&amp;gt;&amp;gt;&amp;gt;    def __init__(self):
&amp;gt;&amp;gt;&amp;gt;        super(Gato, self).__init__()
&amp;gt;&amp;gt;&amp;gt;    def __privado(self):
&amp;gt;&amp;gt;&amp;gt;        &amp;quot;&amp;quot;&amp;quot;Metodo supuestamente privado&amp;quot;&amp;quot;&amp;quot;
&amp;gt;&amp;gt;&amp;gt;        print &amp;quot;Soy privado como los intereses del Estado&amp;#8230;&amp;quot;
&amp;gt;&amp;gt;&amp;gt;    def un_metodo(self):
&amp;gt;&amp;gt;&amp;gt;        &amp;quot;&amp;quot;&amp;quot;Metodo supuestamente publico desde el que se accede a __privado&amp;quot;&amp;quot;&amp;quot;
&amp;gt;&amp;gt;&amp;gt;        self.__privado()
&amp;gt;&amp;gt;&amp;gt;
&amp;gt;&amp;gt;&amp;gt; g1 = Gato()
&amp;gt;&amp;gt;&amp;gt; g1.__privado()
&amp;gt;&amp;gt;&amp;gt; Traceback (most recent call last): 
&amp;gt;&amp;gt;&amp;gt;   File &amp;quot;&amp;lt;interactive input&amp;gt;&amp;quot;, line 1, in ?
&amp;gt;&amp;gt;&amp;gt; AttributeError: 'Gato' object has no attribute '__privado'
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; g1.un_metodo()
Soy privado como los intereses del Estado&amp;#8230;
&amp;gt;&amp;gt;&amp;gt;&lt;/pre&gt;

	&lt;p&gt;Vemos como efectivamente no hemos sido capaces de invocar al m&amp;#233;todo &lt;strong&gt;__privado&lt;/strong&gt; de nuestra clase Gato pero sin embargo al invocar al m&amp;#233;todo &lt;strong&gt;un_metodo&lt;/strong&gt; que llama internamente al m&amp;#233;todo &amp;#8220;&lt;em&gt;__privado&lt;/em&gt;&amp;#8220; si se ha imprimido el mensaje y por lo tanto &amp;#8220;demuestra&amp;#8221; la teor&amp;#237;a explicada por Pilgrim en Dive Into Python.&lt;/p&gt;

	&lt;p&gt;Pero esto no es m&amp;#225;s que una &lt;strong&gt;desagradable coincidencia&lt;/strong&gt;. Que el m&amp;#233;todo no sea accesible desde fuera de la clase no tiene nada que ver con la visibilidad o restricci&amp;#243;n del m&amp;#233;todo sino que es el efecto de un mecanismo de Python conocido como &lt;em&gt;&lt;strong&gt;name mangling&lt;/strong&gt;&lt;/em&gt; (presente en otros lenguajes como C++ o Java) y no sirve para lo que &lt;strong&gt;por error&lt;/strong&gt; se cree de manera popular. Vamos a explicarlo con otro ejemplo en la &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;REPL&lt;/span&gt;&lt;/span&gt;:&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-python&quot;&gt;&amp;gt;&amp;gt;&amp;gt; class Gatico(Gato):
&amp;gt;&amp;gt;&amp;gt;    &amp;quot;&amp;quot;&amp;quot;La clase Gatico hereda de la clase Gato&amp;quot;&amp;quot;&amp;quot;
&amp;gt;&amp;gt;&amp;gt;    def __init__(self):
&amp;gt;&amp;gt;&amp;gt;        super(Gatico, self).__init__()
&amp;gt;&amp;gt;&amp;gt;    def __privado(self):
&amp;gt;&amp;gt;&amp;gt;        &amp;quot;&amp;quot;&amp;quot;Estoy sobreescribiendo el metodo privado?&amp;quot;&amp;quot;&amp;quot;
&amp;gt;&amp;gt;&amp;gt;        print &amp;quot;Es necesario abrir los datos al publico y dejar de ser privado&amp;#8230;&amp;quot;
&amp;gt;&amp;gt;&amp;gt;    def otro_metodo(self):
&amp;gt;&amp;gt;&amp;gt;        &amp;quot;&amp;quot;&amp;quot;Soy otro metodo y me llamo asi a posta para nos sobreescribir a un_metodo de la clase base&amp;quot;&amp;quot;&amp;quot;
&amp;gt;&amp;gt;&amp;gt;        self.__privado()
&amp;gt;&amp;gt;&amp;gt;
&amp;gt;&amp;gt;&amp;gt; g2 = Gatico()
&amp;gt;&amp;gt;&amp;gt; g2.__privado()
&amp;gt;&amp;gt;&amp;gt; Traceback (most recent call last): 
&amp;gt;&amp;gt;&amp;gt;   File &amp;quot;&amp;lt;interactive input&amp;gt;&amp;quot;, line 1, in ?
&amp;gt;&amp;gt;&amp;gt; AttributeError: 'Gatico' object has no attribute '__privado'
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; g2.otro_metodo()
Es necesario abrir los datos al publico y dejar de ser privado&amp;#8230;
&amp;gt;&amp;gt;&amp;gt;
&amp;gt;&amp;gt;&amp;gt; g2.un_metodo()
Soy privado como los intereses del Estado&amp;#8230;
&amp;gt;&amp;gt;&amp;gt;&lt;/pre&gt;

	&lt;p&gt;&amp;#191;Qu&amp;#233; es lo que ha pasado aqu&amp;#237;?. Los programadores de Java y de C++ que est&amp;#225;n leyendo este art&amp;#237;culo (porque lo est&amp;#225;is leyendo verdad, os interesa un mont&amp;#243;n&amp;#8230;) se habr&amp;#225;n percatado r&amp;#225;pidamente de que &lt;strong&gt;algo raro&lt;/strong&gt; est&amp;#225; pasando.&lt;/p&gt;

	&lt;p&gt;En Java no est&amp;#225; permitido sobreescribir m&amp;#233;todos privados, si el programador nombra a un m&amp;#233;todo privado en una clase heredada &lt;strong&gt;exactamente igual&lt;/strong&gt; que un m&amp;#233;todo privado de su clase base, sencillamente estar&amp;#225; creando un m&amp;#233;todo completamente nuevo en la subclase y este ocultar&amp;#225; al m&amp;#233;todo de la superclase.&lt;/p&gt;

	&lt;p&gt;En C++ se puede sobreescribir cualquier m&amp;#233;todo que sea &lt;strong&gt;virtual&lt;/strong&gt;, de hecho, es una pr&amp;#225;ctica aceptada y recomendable sobreescribir solo funciones virtuales privadas y nunca p&amp;#250;blicas pero si sobreescribimos un m&amp;#233;todo privado de una clase base en una subclase y lo invocamos desde la subclase, deber&amp;#237;a de llamarse al m&amp;#233;todo adecuado, es decir, al nuevo m&amp;#233;todo que sobreescribe al de la clase base aunque sea invocado por un m&amp;#233;todo de la clase base desde la subclase. Este es uno de los principios del &lt;strong&gt;polimorfismo&lt;/strong&gt; en C++.&lt;/p&gt;

	&lt;p&gt;Por lo tanto es extra&amp;#241;o que en Python hayamos sobreescrito el m&amp;#233;todo &amp;#8220;&lt;em&gt;__privado&lt;/em&gt;&amp;#8220; pero sin embargo el m&amp;#233;todo &amp;#8220;&lt;em&gt;un_metodo&lt;/em&gt;&amp;#8220; siga pudiendo invocar a la implementaci&amp;#243;n del m&amp;#233;todo &amp;#8220;&lt;em&gt;__privado&lt;/em&gt;&amp;#8220; de su propia clase. De hecho, esto ocurre por que &lt;strong&gt;en ning&amp;#250;n momento hemos sobreescrito&lt;/strong&gt; el m&amp;#233;todo &amp;#8220;&lt;em&gt;__privado&lt;/em&gt;&amp;#8220; de la clase Gato ni es un m&amp;#233;todo privado, ni nunca ha sido intenci&amp;#243;n del lenguaje poder crear m&amp;#233;todos privados ni por &amp;#233;ste &lt;strong&gt;ni por ning&amp;#250;n otro medio&lt;/strong&gt;.&lt;/p&gt;

	&lt;p&gt;&lt;h2&gt;Ahora si que estoy perdido, &amp;#191;me lo explica?&lt;/h2&gt;&lt;br /&gt;

Python es un lenguaje potente que permite al programador hacer pr&amp;#225;cticamente lo que quiera, como por ejemplo, definir algo como &lt;code&gt;True = False&lt;/code&gt; y &lt;strong&gt;liarla parda&lt;/strong&gt; o bien sobreescribir una funci&amp;#243;n&lt;em&gt; builtin&lt;/em&gt;. Esto es as&amp;#237; por la particular visi&amp;#243;n de como debe ser el lenguaje por parte de los Pythonistas y del &lt;strong&gt;&lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;BDFL&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt; (Benevolent Dictator For Life).&lt;/p&gt;

	&lt;p&gt;Uno de los principales valores de Python es que &lt;strong&gt;trata al programador como mayor de edad&lt;/strong&gt; y en lugar de imponer restricciones conf&amp;#237;a en el buen juicio de nosotros, los programadores, para no hacer barbaridades as&amp;#237; que la Comunidad define una serie de &lt;strong&gt;convenciones sobre el lenguaje&lt;/strong&gt;.&lt;/p&gt;

	&lt;p&gt;Entre estas convenciones se encuentra la de nombrar a toda aquella funci&amp;#243;n, todo aquel m&amp;#233;todo o atributo &lt;strong&gt;que no sea parte de la &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt;&lt;/span&gt; p&amp;#250;blica&lt;/strong&gt; (que no m&amp;#233;todos ni propiedades) de nuestra clase, librer&amp;#237;a, framework o m&amp;#243;dulo y sea perceptible a cambios, la desaparici&amp;#243;n o el estado obsoleto y olvidado sin previo aviso, con un underscore delante del nombre para informar a los consumidores de dicha &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt;&lt;/span&gt; de que se trata de un m&amp;#233;todo interno que puede &lt;strong&gt;cambiar sin previo aviso&lt;/strong&gt; y no est&amp;#225; dise&amp;#241;ado (ni es &amp;#250;til) para el uso normal de la &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt;&lt;/span&gt;.&lt;/p&gt;

	&lt;p&gt;Si adem&amp;#225;s el nombre de nuestra variable coincide con una clase, m&amp;#233;todo, variable o &lt;em&gt;builtin&lt;/em&gt; pero es el &amp;#250;nico que tiene l&amp;#243;gica, por ejemplo, &lt;em&gt;list&lt;/em&gt;, &lt;em&gt;sum&lt;/em&gt;, &lt;em&gt;rand&lt;/em&gt; por convenci&amp;#243;n se a&amp;#241;ade un underscore al nombre antes de hacer algo &amp;#8220;&lt;em&gt;tan guarro&lt;/em&gt;&amp;#8220; (para el Zen de Python) como nombrarlo &amp;#8220;&lt;em&gt;lst&lt;/em&gt;&amp;#8220;, &amp;#8220;&lt;em&gt;sm&lt;/em&gt;&amp;#8220;, &amp;#8220;&lt;em&gt;rnd&lt;/em&gt;&amp;#8220; que no aporta valor sem&amp;#225;ntico.&lt;/p&gt;

	&lt;p&gt;Por otro lado, para posibilitar que las clases que heredan de clases bases puedan sobreescribir m&amp;#233;todos &lt;strong&gt;sin romper las llamadas internas&lt;/strong&gt; de sus clases base a dichos m&amp;#233;todos, cualquier m&amp;#233;todo (o funci&amp;#243;n o atributo) que comience con al menos dos underscores (y no acabe en dos underscores, uno si est&amp;#225; permitido) es &lt;strong&gt;renombrado por el int&amp;#233;rprete&lt;/strong&gt; en la definici&amp;#243;n de la clase siguiendo la siguiente norma &amp;#8220;&lt;em&gt;_classname__methodname&lt;/em&gt;&amp;#8220; as&amp;#237; que para nuestro ejemplo el m&amp;#233;todo quedar&amp;#237;a as&amp;#237; &amp;#8220;&lt;em&gt;_Gato__privado&lt;/em&gt;&amp;#8220; y de hecho podr&amp;#237;a seguir siendo invocado desde fuera de la clase si as&amp;#237; lo queremos:&lt;br /&gt;

&lt;pre class=&quot;prettyprint lang-python&quot;&gt;&lt;code&gt;&amp;amp;gt;&amp;amp;gt;&amp;amp;gt; g1._Gato__privado()
Soy privado como los intereses del Estado...&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

	&lt;p&gt;Y puede ser invocado ya que nunca fue la intenci&amp;#243;n del lenguaje que existieran los m&amp;#233;todos privados, ya que en Python, por su propia condici&amp;#243;n de lenguaje din&amp;#225;mico y sus caracter&amp;#237;sticas, no es necesario. Asimismo, los m&amp;#233;todos, funciones o variables que empiezan con un underscore &lt;strong&gt;no son importados&lt;/strong&gt; al usar &lt;code&gt;from bleh import *&lt;/code&gt; que por otro lado es una sintaxis considerada &amp;#8220;&lt;em&gt;deprectaed&lt;/em&gt;&amp;#8220; y mala pr&amp;#225;ctica de programaci&amp;#243;n por el &lt;span class=&quot;caps&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PEP&lt;/span&gt;&lt;/span&gt;-8.&lt;/p&gt;

	&lt;p&gt;&lt;h2&gt;Conclusi&amp;#243;n&lt;/h2&gt;&lt;br /&gt;

Ya se que ha sido un &lt;strong&gt;art&amp;#237;culo ladrillazo&lt;/strong&gt; pero considero que en vista a la falta total de literatura al respecto era necesario realizar esta aclaraci&amp;#243;n para ayudar as&amp;#237; a comprender mejor este maravilloso lenguaje.&lt;/p&gt;

	&lt;p&gt;En breve escribir&amp;#233; otro art&amp;#237;culo explicando porque no es necesario el uso de m&amp;#233;todos o propiedades privados. Hasta entonces, happy hacking.&lt;/p&gt;

	&lt;p&gt;M&amp;#225;s Desinformaci&amp;#243;n | &lt;a href=&quot;http://www.diveintopython.net/object_oriented_framework/private_functions.html&quot;&gt;Cap&amp;#237;tulo 5.9. de Dive Into Python&lt;/a&gt;&lt;/p&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://pybonacci.wordpress.com/?p=371
            </guid>
            <title>
                Pybonacci: Sage: software matem&amp;#225;tico libre como alternativa
            </title>
            <pubDate>
                Sun, 06 May 2012 18:15:42 GMT
            </pubDate>
            <link>
                http://pybonacci.wordpress.com/2012/05/06/sage-software-matematico-libre-como-alternativa/
            </link>
            <description>
                &lt;p&gt;Seguro que muchos de vosotros ya conoc&amp;#233;is&amp;#160;&lt;a href=&quot;http://sagemath.org/&quot;&gt;Sage&lt;/a&gt;: un proyecto cuyo nada ambicioso objetivo es&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Crear una alternativa&amp;#160;de c&amp;#243;digo abierto, libre y viable a Magma, Maple, Mathematica y MATLAB.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Desde luego hay que admitir que como declaraci&amp;#243;n de intenciones no est&amp;#225; mal. Hechas las presentaciones, &amp;#191;qu&amp;#233; m&amp;#225;s podemos decir sobre Sage?&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://pybonacci.files.wordpress.com/2012/05/sage-logo-new-l.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-373&quot; src=&quot;https://pybonacci.files.wordpress.com/2012/05/sage-logo-new-l.png?w=700&quot; title=&quot;Logo de Sage&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Sage comenz&amp;#243; en 2004 como un proyecto personal de &lt;a href=&quot;http://www.wstein.org/&quot;&gt;William Stein&lt;/a&gt;, profesor de matem&amp;#225;ticas en la Universidad de Washington, quien, &lt;a href=&quot;http://sagemath.blogspot.com.es/2009/12/mathematical-software-and-me-very.html&quot;&gt;como explica en su blog&lt;/a&gt;, estaba frustrado por no poder solucionar las limitaciones de Magma al no ser un programa libre. Stein se dio cuenta de que, aunque crear un sistema como Magma o Maple llevar&amp;#237;a a&amp;#241;os con un equipo de desarrolladores voluntarios partiendo de cero,&lt;em&gt; ya hab&amp;#237;a numerosos paquetes de c&amp;#243;digo abierto&lt;/em&gt; escritos en diferentes lenguajes enfocados a diversas &amp;#225;reas matem&amp;#225;ticas. As&amp;#237; que decidi&amp;#243; unir todos estos paquetes &lt;strong&gt;utilizando Python&lt;/strong&gt; (en este momento son &lt;a href=&quot;http://sagemath.org/links-components.html&quot;&gt;cerca de 100&lt;/a&gt;) para crear un enorme software matem&amp;#225;tico para crear Sage. En esto se diferencia de otros proyectos como SymPy, del que ya &lt;a href=&quot;http://pybonacci.wordpress.com/2012/04/04/introduccion-al-calculo-simbolico-en-python-con-sympy/&quot;&gt;hemos&lt;/a&gt; &lt;a href=&quot;http://pybonacci.wordpress.com/2012/04/30/como-calcular-limites-derivadas-series-e-integrales-en-python-con-sympy/&quot;&gt;hablado&lt;/a&gt; en este blog.&lt;/p&gt;
&lt;p&gt;&lt;span id=&quot;more-371&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;En este momento Sage ha visto m&amp;#225;s de 300 versiones y cuenta con&amp;#160;&lt;a href=&quot;http://sagemath.org/development-map.html&quot;&gt;m&amp;#225;s de 200 colaboradores por todo el mundo&lt;/a&gt;. Adem&amp;#225;s, desde febrero de 2006 se han celebrado numerosos eventos, conocidos como &lt;a href=&quot;http://wiki.sagemath.org/Workshops&quot;&gt;&amp;#171;Sage Days&amp;#187;&lt;/a&gt;, en los que los desarrolladores se han reunido para solucionar errores, implementar nuevas caracter&amp;#237;sticas, escribir documentaci&amp;#243;n o hablar sobre el uso de Sage en educaci&amp;#243;n.&lt;/p&gt;
&lt;p&gt;Hablando de eventos, en Espa&amp;#241;a desde hace dos a&amp;#241;os se celebran cada verano las &lt;strong&gt;Jornadas Sage/Python&lt;/strong&gt;, en las que se muestran las experiencias docentes que ya se est&amp;#225;n llevando a cabo con este programa en algunas universidades espa&amp;#241;olas y se explican ejemplos de aplicaci&amp;#243;n. Este a&amp;#241;o se celebrar&amp;#225;n las &lt;a href=&quot;http://webs.uvigo.es/sage2012/&quot;&gt;III Jornadas Sage/Python en la Universidad de Vigo&lt;/a&gt;&amp;#160;los d&amp;#237;as 21 y 22 de junio de 2012 y est&amp;#225;is todos invitados &lt;img alt=&quot;:)&quot; class=&quot;wp-smiley&quot; src=&quot;http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif&quot; /&gt; &lt;/p&gt;
&lt;p&gt;Sage dispone de una &lt;a href=&quot;http://sagemath.org/doc/&quot;&gt;documentaci&amp;#243;n&lt;/a&gt; &lt;em&gt;enorme&lt;/em&gt; compuesta de tutoriales, gu&amp;#237;as y el &lt;a href=&quot;http://sagemath.org/doc/reference/index.html&quot;&gt;manual de referencia&lt;/a&gt;. Solo por el tama&amp;#241;o de este &amp;#250;ltimo nos damos cuenta de la sorprendente amplitud de posibilidades que tiene este programa. Actualmente Sage le lleva la delantera a todos sus competidores no libres en cuanto a temas de matem&amp;#225;tica te&amp;#243;rica, como pueden ser &lt;a href=&quot;http://sagemath.org/doc/reference/plane_curves.html&quot;&gt;curvas el&amp;#237;pticas&lt;/a&gt;&amp;#160;o &lt;a href=&quot;http://sagemath.org/doc/reference/matrices.html&quot;&gt;espacios de matrices&lt;/a&gt;, y por supuesto es capaz de dibujar gr&amp;#225;ficos en 2D y en 3D y de crear componentes interactivos al estilo de Mathematica, con la diferencia que para compartirlos no necesitas el Mathematica Player: &lt;a href=&quot;http://aleph.sagemath.org/?z=eJyNkc9OhDAQxu88xZd4YAa7CKwe1qSJJ1_CmKYusFtDylqKvr5TQA970R6m8_c3X9NPGyhvo4IdLmer4HPOgqmpjQyNGndoUIBq7LAXp41L5hbTR4h0lWYUxVJslhQnUvMHafdP0kxJpN90JiItnozJEpYhEtk_UYEUCMMLYytsg9eNtKt57Sxg3yZa0xJnRrRoVGWdmXVVCg7Zk_OxC_YYs7brYUjaNEmXgthKrqasmBXWoVQ6qLSlfFAQw8yPGeRM5_GLBjdFcxnGSC_kRIFJr5zLaRYlwjW_P6NXHJPXjhn9GODgPIL1p47uK35VSJz30fmu1c92mDqF4ziMQec3VbXf933O_A33GX0V&quot;&gt;solamente un navegador&lt;/a&gt;. En la Wikipedia podemos leer una extensa lista de caracter&amp;#237;sticas:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Algunos de las muchas caracter&amp;#237;sticas de Sage incluyen:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Una interfaz gr&amp;#225;fica (notebook) para la revisi&amp;#243;n y reutilizaci&amp;#243;n de entradas y salidas anteriores, incluyendo gr&amp;#225;ficas y notas de texto disponibles en la mayor&amp;#237;a de los navegadores web incluyendo&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Firefox&quot; title=&quot;Firefox&quot;&gt;Firefox&lt;/a&gt;,&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Opera_(navegador)&quot; title=&quot;Opera (navegador)&quot;&gt;Opera&lt;/a&gt;,&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Konqueror&quot; title=&quot;Konqueror&quot;&gt;Konqueror&lt;/a&gt;, y&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Safari&quot; title=&quot;Safari&quot;&gt;Safari&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Una l&amp;#237;nea de comandos basada en texto usando&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/IPython&quot; title=&quot;IPython&quot;&gt;iPython&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;El&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Lenguaje_de_programaci%C3%B3n_Python&quot; title=&quot;Lenguaje de programaci&amp;#243;n Python&quot;&gt;lenguaje de programaci&amp;#243;n Python&lt;/a&gt;, que soporta expresiones en programaci&amp;#243;n&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Programaci%C3%B3n_orientada_a_objetos&quot; title=&quot;Programaci&amp;#243;n orientada a objetos&quot;&gt;orientada a objetos&lt;/a&gt;&amp;#160;y&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Programaci%C3%B3n_funcional&quot; title=&quot;Programaci&amp;#243;n funcional&quot;&gt;funcional&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://es.wikipedia.org/wiki/Computaci%C3%B3n_paralela&quot; title=&quot;Computaci&amp;#243;n paralela&quot;&gt;Procesamiento paralelo&lt;/a&gt;&amp;#160;usando tanto&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/w/index.php?title=Procesadores_de_n%C3%BAcleo_m%C3%BAltiple&amp;amp;action=edit&amp;amp;redlink=1&quot; title=&quot;Procesadores de n&amp;#250;cleo m&amp;#250;ltiple (a&amp;#250;n no redactado)&quot;&gt;procesadores de n&amp;#250;cleo m&amp;#250;ltiple&lt;/a&gt;&amp;#160;como&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/w/index.php?title=Multiprocesadores_sim%C3%A9tricos&amp;amp;action=edit&amp;amp;redlink=1&quot; title=&quot;Multiprocesadores sim&amp;#233;tricos (a&amp;#250;n no redactado)&quot;&gt;multiprocesadores sim&amp;#233;tricos&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;C&amp;#225;lculo usando&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Maxima&quot; title=&quot;Maxima&quot;&gt;Maxima&lt;/a&gt;&amp;#160;y&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/SymPy&quot; title=&quot;SymPy&quot;&gt;SymPy&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&amp;#193;lgebra lineal num&amp;#233;rica usando&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/GNU_Scientific_Library&quot; title=&quot;GNU Scientific Library&quot;&gt;GSL&lt;/a&gt;,&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/SciPy&quot; title=&quot;SciPy&quot;&gt;SciPy&lt;/a&gt;&amp;#160;y&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/NumPy&quot; title=&quot;NumPy&quot;&gt;NumPy&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Control interactivo de los c&amp;#225;lculos&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Librer&amp;#237;as de funciones&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Funci%C3%B3n_elemental&quot; title=&quot;Funci&amp;#243;n elemental&quot;&gt;elementales&lt;/a&gt;&amp;#160;y&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Funci%C3%B3n_especial&quot; title=&quot;Funci&amp;#243;n especial&quot;&gt;especiales&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Gr&amp;#225;ficas en 2D y 3D tanto de funciones como de datos.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Herramientas de manipulaci&amp;#243;n de datos y matrices.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Librer&amp;#237;as de&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Estad%C3%ADstica&quot; title=&quot;Estad&amp;#237;stica&quot;&gt;estad&amp;#237;stica&lt;/a&gt;&amp;#160;multivariable&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Una caja de herramientas para a&amp;#241;adir&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Interfaz_de_usuario&quot; title=&quot;Interfaz de usuario&quot;&gt;interfaces de usuario&lt;/a&gt;&amp;#160;a c&amp;#225;lculos y aplicaciones&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Herramientas para&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Procesamiento_de_im%C3%A1genes&quot; title=&quot;Procesamiento de im&amp;#225;genes&quot;&gt;procesamiento de im&amp;#225;genes&lt;/a&gt;&amp;#160;usando pylab as&amp;#237; como Python&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Herramientas para visualizar y analizar&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Gr%C3%A1fica&quot; title=&quot;Gr&amp;#225;fica&quot;&gt;gr&amp;#225;ficas&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Librer&amp;#237;as para funciones de teor&amp;#237;a de n&amp;#250;meros&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Filtros para importar y exportar datos, im&amp;#225;genes, v&amp;#237;deo, sonido,&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/CAD&quot; title=&quot;CAD&quot;&gt;CAD&lt;/a&gt;, y&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/GIS&quot; title=&quot;GIS&quot;&gt;GIS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Soporte para&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/N%C3%BAmeros_complejos&quot; title=&quot;N&amp;#250;meros complejos&quot;&gt;n&amp;#250;meros complejos&lt;/a&gt;,&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/w/index.php?title=Aritm%C3%A9tica_de_precisi%C3%B3n_arbitraria&amp;amp;action=edit&amp;amp;redlink=1&quot; title=&quot;Aritm&amp;#233;tica de precisi&amp;#243;n arbitraria (a&amp;#250;n no redactado)&quot;&gt;aritm&amp;#233;tica de precisi&amp;#243;n arbitraria&lt;/a&gt;, y computaci&amp;#243;n simb&amp;#243;lica de funciones donde esto sea apropiado.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Embeber Sage en documentos&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/LaTeX&quot; title=&quot;LaTeX&quot;&gt;LaTeX&lt;/a&gt;&lt;span style=&quot;font-size: 11px;&quot;&gt;.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Interfaces a otro software como&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Mathematica&quot; title=&quot;Mathematica&quot;&gt;Mathematica&lt;/a&gt;,&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Magma&quot; title=&quot;Magma&quot;&gt;Magma&lt;/a&gt;&amp;#160;y&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Maple&quot; title=&quot;Maple&quot;&gt;Maple&lt;/a&gt;, que le permite a los usuarios combinar software y comparar resultados y desempe&amp;#241;o.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;p&gt;&amp;#191;Alguien habl&amp;#243; de interfaz gr&amp;#225;fica? &amp;#161;S&amp;#237;! Sage tiene una interfaz a imitaci&amp;#243;n de los &amp;#171;notebooks&amp;#187; de Mathematica que funciona a trav&amp;#233;s del navegador, y que adem&amp;#225;s permite la edici&amp;#243;n colaborativa de documentos. Puedes utilizarla con el programa, montar tu propio servidor o crear una cuenta en el &lt;a href=&quot;http://www.sagenb.org/&quot;&gt;servidor p&amp;#250;blico de Sage&lt;/a&gt; para empezar a experimentar.&lt;/p&gt;
&lt;div class=&quot;wp-caption aligncenter&quot; id=&quot;attachment_378&quot; style=&quot;width: 430px;&quot;&gt;&lt;a href=&quot;https://pybonacci.files.wordpress.com/2012/05/2012-05-06-195446_1366x768_scrot.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot; wp-image-378&quot; height=&quot;236&quot; src=&quot;https://pybonacci.files.wordpress.com/2012/05/2012-05-06-195446_1366x768_scrot.png?w=420&amp;amp;h=236&quot; title=&quot;Interfaz gr&amp;#225;fica de Sage&quot; width=&quot;420&quot; /&gt;&lt;/a&gt;&lt;p class=&quot;wp-caption-text&quot;&gt;Ejemplo de c&amp;#243;mo se ve un &amp;#171;notebook&amp;#187; en la interfaz de Sage (vista p&amp;#250;blica en http://sagenb.org/home/pub/3319/)&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Es complicado hacer una introducci&amp;#243;n a este programa porque es bastante inabarcable, pero espero que te haya resultado interesante. Si te apetece saber m&amp;#225;s cosas sobre Sage, puedes consultar &lt;a href=&quot;http://www.sagenb.org/home/pub/873/&quot;&gt;este &amp;#171;notebook&amp;#187; p&amp;#250;blico&lt;/a&gt;&amp;#160;que explica algunas de sus posibilidades (e incluso editarlo t&amp;#250; mismo). O puedes estar atento a futuras publicaciones en Pybonacci &lt;img alt=&quot;;)&quot; class=&quot;wp-smiley&quot; src=&quot;http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif&quot; /&gt; &lt;/p&gt;
&lt;p&gt;&amp;#161;Un saludo!&lt;/p&gt;
&lt;br /&gt;Filed under: &lt;a href=&quot;http://pybonacci.wordpress.com/category/recursos/&quot;&gt;Recursos&lt;/a&gt; Tagged: &lt;a href=&quot;http://pybonacci.wordpress.com/tag/calculo-simbolico/&quot;&gt;c&amp;#225;lculo simb&amp;#243;lico&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/notebook/&quot;&gt;notebook&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/python/&quot;&gt;python&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/sage/&quot;&gt;sage&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gocomments/pybonacci.wordpress.com/371/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/comments/pybonacci.wordpress.com/371/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godelicious/pybonacci.wordpress.com/371/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/delicious/pybonacci.wordpress.com/371/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gofacebook/pybonacci.wordpress.com/371/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/facebook/pybonacci.wordpress.com/371/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gotwitter/pybonacci.wordpress.com/371/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/twitter/pybonacci.wordpress.com/371/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gostumble/pybonacci.wordpress.com/371/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/stumble/pybonacci.wordpress.com/371/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godigg/pybonacci.wordpress.com/371/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/digg/pybonacci.wordpress.com/371/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/goreddit/pybonacci.wordpress.com/371/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/reddit/pybonacci.wordpress.com/371/&quot; /&gt;&lt;/a&gt; &lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://stats.wordpress.com/b.gif?host=pybonacci.wordpress.com&amp;#038;blog=33759577&amp;#038;post=371&amp;#038;subd=pybonacci&amp;#038;ref=&amp;#038;feed=1&quot; width=&quot;1&quot; /&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://python.majibu.org/preguntas/1484/enlaces-temporales-con-django
            </guid>
            <title>
                python majibu: Enlaces temporales con Django?
            </title>
            <pubDate>
                Wed, 02 May 2012 19:33:51 GMT
            </pubDate>
            <link>
                http://python.majibu.org/preguntas/1484/enlaces-temporales-con-django
            </link>
            <description>
                &lt;p&gt;Hola! :D
no s&amp;#233; nada de django, quiero estudiarlo en est&amp;#225; semana. A&amp;#250;n as&amp;#237; tengo una pregunta que me mata de la curiosidad: &amp;#191;es posible crear enlaces temporables para contenido descargable? La idea es b&amp;#225;sicamente crear un enlace y que luego de un determinado n&amp;#250;mero de descargas del archivo, dicho enlace sea inservible. No busco un ejemplo completo, con ver como crear e invalidar el enlace satisfacer&amp;#237;a mi curiosidad.&lt;/p&gt;
&lt;p&gt;Saludos!&lt;/p&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://www.genbetadev.com/frameworks/otro-que-cae-en-las-garras-de-github-django
            </guid>
            <title>
                Genbeta:dev: Otro que cae en las garras de Github, Django
            </title>
            <pubDate>
                Tue, 01 May 2012 15:08:49 GMT
            </pubDate>
            <link>
                http://www.genbetadev.com/frameworks/otro-que-cae-en-las-garras-de-github-django
            </link>
            <description>
                &lt;p&gt;&lt;img alt=&quot;django github&quot; class=&quot;centro_sinmarco&quot; src=&quot;http://img.genbetadev.com/2012/05/650_1000_Captura de pantalla 2012-05-01 a las 18.59.15.png&quot; /&gt;&lt;/p&gt;

	&lt;p&gt;Y con &lt;strong&gt;Django&lt;/strong&gt; no nos referimos, claro est&amp;#225;, ni al &lt;a href=&quot;http://es.wikipedia.org/wiki/Dyango&quot;&gt;afamado cantante espa&amp;#241;ol&lt;/a&gt; ni al popular personaje del &lt;a href=&quot;http://www.imdb.com/title/tt0060315/&quot;&gt;spaguetti-western&lt;/a&gt; interpretado por Franco Nero. No, nada de eso, Django es el poderoso y cada d&amp;#237;a m&amp;#225;s conocido &lt;strong&gt;framework de desarrollo web en Python&lt;/strong&gt; (por ejemplo, el chico de moda &lt;a href=&quot;http://www.genbetadev.com/python/las-tecnologias-que-usa-el-hype-del-momento-pinterest&quot;&gt;Pinterest lo lleva en sus entra&amp;#241;as&lt;/a&gt;) y que en los &amp;#250;ltimos d&amp;#237;as &lt;strong&gt;ha abandonado definitivamente Subversi&amp;#243;n&lt;/strong&gt;, sistema de control de versiones que utiliza desde sus albores, all&amp;#225; por 2005, para pasarse a Git y &lt;strong&gt;compartir su c&amp;#243;digo en Github&lt;/strong&gt;.&lt;/p&gt;

	&lt;p&gt;De hecho la gente del &lt;a href=&quot;https://www.djangoproject.com/&quot;&gt;Django Project&lt;/a&gt; ya ten&amp;#237;a un repositorio en Github pero lo que compart&amp;#237;an eran versiones siempre muy antiguas y desfasadas de su c&amp;#243;digo. Ahora eso ha cambiado y han decidido unirse al gran &lt;em&gt;hype&lt;/em&gt; que hay alrededor de este popular repositorio de c&amp;#243;digo por lo que todos los &lt;em&gt;pythonistas&lt;/em&gt; pueden encontrar a partir de ahora &lt;strong&gt;versiones muy actualizadas y calentitas con las que jugar&lt;/strong&gt;.&lt;/p&gt;

	&lt;p&gt;Y lo cierto es que, despu&amp;#233;s de echarle un vistazo a este repositorio en Github de Django, esta gente tiene &lt;strong&gt;un c&amp;#243;digo de mucha calidad&lt;/strong&gt;. Realmente da gusto, si te gusta leer c&amp;#243;digo (oye, cada uno tiene sus vicios), pasearte por su &amp;#225;rbol de ficheros e ir abriendo cada uno e indagando en &amp;#233;l (aunque, como es mi caso, ni siquiera tengas gran idea de Python). Un gran trabajo al que ahora &lt;strong&gt;todos podemos acceder y contribuir&lt;/strong&gt;. &lt;/p&gt;

	&lt;p&gt;V&amp;#237;a | &lt;a href=&quot;http://net.tutsplus.com/articles/news/recently-in-web-development-april-%E2%80%9912-edition/&quot;&gt;Nettus+&lt;/a&gt;&lt;br /&gt;
Descarga | &lt;a href=&quot;https://github.com/django/django&quot;&gt;Github&lt;/a&gt;&lt;br /&gt;
En Genbeta Dev | &lt;a href=&quot;http://www.genbetadev.com/sistemas-de-control-de-versiones/otro-proyecto-mas-que-migra-a-github-ahora-spring-framework&quot;&gt;Otro proyecto m&amp;#225;s que migra a GitHub: ahora Spring Framework&lt;/a&gt;&lt;/p&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://pybonacci.wordpress.com/?p=348
            </guid>
            <title>
                Pybonacci: Python es lento
            </title>
            <pubDate>
                Tue, 01 May 2012 01:11:32 GMT
            </pubDate>
            <link>
                http://pybonacci.wordpress.com/2012/05/01/python-es-lento/
            </link>
            <description>
                &lt;p&gt;La programaci&amp;#243;n cient&amp;#237;fica consiste, en su mayor parte, en c&amp;#225;lculos num&amp;#233;ricos intensos. CPU en estado puro. Un lenguaje interpretado es, por construcci&amp;#243;n, m&amp;#225;s lento que su hom&amp;#243;logo compilado, por lo que puede parecer un contrasentido usar Python para aplicaciones &amp;#171;pesadas&amp;#187;.&amp;#160; Estamos perdiendo el tiempo, &amp;#191;o no?&lt;/p&gt;
&lt;p&gt;Muchos programas cient&amp;#237;ficos se ejecutan s&amp;#243;lo una vez, son un c&amp;#225;lculo concreto que no har&amp;#225; falta repetir. La mayor parte del tiempo del c&amp;#225;lculo no es la ejecuci&amp;#243;n del programa, sino escribirlo, trabajo de un humano. Aqu&amp;#237; es donde entran las bondades de Python: es sencillo, r&amp;#225;pido de escribir, y potente como el que m&amp;#225;s. Y, por lo sencillo que eso, aunque sea de naturaleza lenta (o precisamente por eso), se han creado muchas herramientas para mejorar su eficiencia de formas elegantes y pyth&amp;#243;nicas.&lt;/p&gt;
&lt;p&gt;Muchas cr&amp;#237;ticas sobre la lentitud de Python adolecen de alguno de estos problemas:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Benchmarks&lt;/em&gt; irreales o incorrectos: &amp;#191;qui&amp;#233;n necesita un programa para imprimir &lt;a href=&quot;http://theunixgeek.blogspot.com.es/2008/09/c-vs-python-speed.html&quot;&gt;el primer mill&amp;#243;n de n&amp;#250;meros naturales&lt;/a&gt;?&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/6964392/speed-comparison-with-project-euler-c-vs-python-vs-erlang-vs-haskell&quot;&gt;Desconocimiento del lenguaje.&lt;/a&gt; A veces hay formas mejores de hacer las cosas, m&amp;#225;s sencillas y &amp;#243;ptimas.&lt;/li&gt;
&lt;li&gt;Se limitan a la biblioteca est&amp;#225;ndar, que se queda coja para el c&amp;#225;lculo num&amp;#233;rico (como veremos m&amp;#225;s adelante).&lt;/li&gt;
&lt;li&gt;No tienen en cuenta el tiempo necesario para escribirlo y depurarlo. Cuanto m&amp;#225;s largo sea el programa, m&amp;#225;s dif&amp;#237;cil ser&amp;#225; encontrar los problemas o a&amp;#241;adirle nuevas funcionalidades (tiempo del programador).&lt;/li&gt;
&lt;li&gt;Por lo tanto, usar un lenguaje de m&amp;#225;s alto nivel permite, a igualdad de inteligencia, tiempo y habilidad, crear un programa potencialmente m&amp;#225;s complejo y eficiente.&lt;/li&gt;
&lt;li&gt;No son guays (pero nosotros s&amp;#237;).&lt;span id=&quot;more-348&quot;&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;En este art&amp;#237;culo pretendo hacer un repaso no exhaustivo y no muy riguroso de las principales formas de acelerar c&amp;#243;digo Python para un cient&amp;#237;fico. La mayor&amp;#237;a requieren la instalaci&amp;#243;n de bibliotecas espec&amp;#237;ficas, y algunas de ellas, una configuraci&amp;#243;n cuidadosa, por lo que no todas son adecuadas para distribuir un producto al p&amp;#250;blico general. Vamos all&amp;#225;:&lt;/p&gt;
&lt;h2&gt;&lt;/h2&gt;
&lt;h2&gt;Optimiza, que algo queda.&lt;/h2&gt;
&lt;p&gt;Antes de empezar a pensar en optimizar debemos saber &lt;em&gt;qu&amp;#233;&lt;/em&gt; optimizar. Si tenemos una rutina simple, es obvio, pero si el programa es complejo, no es trivial ver por d&amp;#243;nde atacarlo. Podemos tirarnos horas tratando de mejorar el tiempo de una funci&amp;#243;n que, de varias horas de simulaci&amp;#243;n, s&amp;#243;lo se lleva cinco minutos, mientras que cambiando una l&amp;#237;nea, podemos obtener una mejora del 33% (historia real).&lt;/p&gt;
&lt;p&gt;Por lo tanto, antes de meter la zarpa de optimizaci&amp;#243;n debemos saber d&amp;#243;nde se est&amp;#225; empleando nuestro tiempo. Eso se hace con sistemas de &lt;em&gt;profiling&lt;/em&gt; (&lt;a href=&quot;http://docs.python.org/library/profile.html&quot;&gt;v&amp;#233;anse &lt;/a&gt;&lt;a href=&quot;https://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Examples&quot;&gt;algunos&lt;/a&gt; &lt;a href=&quot;http://wiki.jrfonseca.googlecode.com/git/gprof2dot.png&quot;&gt;ejemplos&lt;/a&gt;). Otro d&amp;#237;a trataremos este tema.&lt;/p&gt;
&lt;h2&gt;&lt;/h2&gt;
&lt;h2&gt;&lt;strong&gt;Conociendo el lenguaje: &lt;em&gt;list comprehension&lt;/em&gt;&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Como dec&amp;#237;a al principio, conocer el lenguaje es importante a la hora de escribir c&amp;#243;digo eficiente, y Python guarda algunas sorpresas. Por ejemplo, sacar cosas por pantalla es lento, no imprimas todo lo que va haciendo, ser&amp;#225; m&amp;#225;s r&amp;#225;pido (y m&amp;#225;s &amp;#250;til) imprimir s&amp;#243;lo una docena de marcas clave, para saber por d&amp;#243;nde va.&lt;/p&gt;
&lt;p&gt;Otro de los pozos de tiempo son los bucles. La mayor&amp;#237;a de las veces son inevitables, pero a veces hay opciones m&amp;#225;s r&amp;#225;pidas. Imagina que queremos construir una lista resultado de aplicar una funci&amp;#243;n a todos los elementos de una lista. Una forma obvia de hacerlo es:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
lis2=[]
for element in lis:
   lis2.append(f(element))
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Pero la opci&amp;#243;n idiom&amp;#225;tica, usando list comprehensions, es:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
# Una list comprehension b&amp;#225;sica:
lis2=[f(element) for element in lis]
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;O incluso, restringiendo el dominio:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
# S&amp;#243;lo a los elementos positivos.
lis2=[f(element) for element in lis if element&amp;gt;0]
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Que es substancialmente m&amp;#225;s r&amp;#225;pido.&lt;/p&gt;
&lt;p style=&quot;text-align: right;&quot;&gt;# Sugerencia avanzada: los comandos map y filter.&lt;/p&gt;
&lt;h2&gt;&lt;/h2&gt;
&lt;h2&gt;Optimizaci&amp;#243;n autom&amp;#225;gica: Psyco&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;http://psyco.sourceforge.net/&quot;&gt;Psyco&lt;/a&gt; es un compilador JIT (&lt;em&gt;just in time&lt;/em&gt;, &amp;#171;en tiempo real&amp;#187;), que optimiza en tiempo de ejecuci&amp;#243;n el c&amp;#243;digo.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Cuando el compilador JIT detecta un bucle [funci&amp;#243;n] en el c&amp;#243;digo [...] se le hace un seguimiento.&amp;#160; Cuando esa funci&amp;#243;n sea ejecutada, el int&amp;#233;rprete la inspecciona y registra todas las instrucciones ejecutadas.&lt;/p&gt;
&lt;p&gt;Cuando ha finalizado, el seguimiento se detiene y el registro es mandado a un optimizador, y de ah&amp;#237; a un ensamblador que genera c&amp;#243;digo m&amp;#225;quina optimizado. La pr&amp;#243;xima vez que se ejecute esa pieza de c&amp;#243;digo, se usar&amp;#225; esta versi&amp;#243;n mejorada.&lt;/p&gt;
&lt;p&gt;(El c&amp;#243;digo) depende de varias suposiciones sobre el c&amp;#243;digo que van incluidas en la versi&amp;#243;n optimizada. Si alguna de esas suposiciones falla, la ejecuci&amp;#243;n pasa de nuevo a la versi&amp;#243;n original.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;text-align: right;&quot;&gt;&lt;em&gt;(Extra&amp;#237;do del blog de &lt;a href=&quot;http://www.huyng.com/posts/so-thats-how-tracing-jits-work/&quot;&gt;Huy Nguyen &lt;/a&gt;citando a su vez &lt;a href=&quot;http://morepypy.blogspot.com.es/2011/04/tutorial-part-2-adding-jit.html&quot;&gt;el blog de PyPy&lt;/a&gt;)&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;El uso no podr&amp;#237;a ser m&amp;#225;s sencillo. S&amp;#237;mplemente a&amp;#241;ade al principio de tu programa:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
import psyco
psyco.full()
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Y obtiene una aceleraci&amp;#243;n de un factor 2-3, que puede llegar hasta un factor 10 para el c&amp;#225;lculo num&amp;#233;rico puro. La gran ventaja de Psyco es que no requiere hacer modificaciones espec&amp;#237;ficas en el c&amp;#243;digo: a&amp;#241;&amp;#225;delo y funciona. En casi todas partes. Y ya.&lt;/p&gt;
&lt;p&gt;Pero no es siempre &amp;#250;til. Por ejemplo, cuando hacemos uso intensivo de NumPy, el c&amp;#243;digo ya est&amp;#225; optimizado, as&amp;#237; que Psyco poco puede rascar, y su &amp;#250;nico efecto es ralentizar el programa (en cantidades inapreciables, eso s&amp;#237;). Adem&amp;#225;s, tras a&amp;#241;os en los que s&amp;#243;lo ha recibido mantenimiento b&amp;#225;sico (nadie lleg&amp;#243; a portarlo a Python 2.7 ni a las versiones de 64 bits), desde el 12 de marzo est&amp;#225; definitivamente muerto.&amp;#160; Hubo en alg&amp;#250;n momento una distribuci&amp;#243;n de la Psyco 2, prometiendo una p&amp;#225;gina web y nuevas caracter&amp;#237;sticas, pero nunca m&amp;#225;s se supo, y hace que otras bibliotecas como Matplotlib dejen de funcionar. Es mejor quedarse con la vieja versi&amp;#243;n 1.7.&lt;/p&gt;
&lt;p&gt;Espera, &amp;#191;he dicho NumPy? &amp;#191;qu&amp;#233; es NumPy?&lt;/p&gt;
&lt;h2&gt;&lt;/h2&gt;
&lt;h2&gt;NumPy y SciPy&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;http://scipy.org/&quot;&gt;La Biblia&lt;/a&gt; cuando hablamos de c&amp;#225;lculo num&amp;#233;rico en Python. Su mayor contribuci&amp;#243;n es una nueva estructura de datos: el array. Una lista (multidimensional) homog&amp;#233;nea, en la que todos sus elementos han de ser del mismo tipo: entero, decimal en precisi&amp;#243;n arbitraria, complejo&amp;#8230; y sobre la que se puede aplicar una gran cantidad de funciones. Veamos un ejemplo: &amp;#191;cu&amp;#225;l es la suma de las ra&amp;#237;ces cuadradas de los diez primeros n&amp;#250;meros y los senos de esos mismos n&amp;#250;meros?&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
# Implementaci&amp;#243;n est&amp;#225;ndar
import psyco
psyco.full()

import math
numbers=range(10)

result=[math.sqrt(num)+math.sin(num) for num in numbers]
&lt;/pre&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: python;&quot;&gt;
# Implementaci&amp;#243;n con NumPy
import numpy as np
numbers=np.range(10)

result=np.sqrt(numbers)+np.sin(numbers)
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Como vemos, ya no hace falta ir elemento a elemento, sino que le podemos dar la lista completa, y &amp;#233;l solo hace la iteraci&amp;#243;n. Esto no es s&amp;#243;lo una cuesti&amp;#243;n de conveniencia, sino que tambi&amp;#233;n permite incrementar la velocidad de ejecuci&amp;#243;n. En algunas operaciones, como las matriciales, esto es incluso m&amp;#225;s interesante, ya que de forma completamente transparente y autom&amp;#225;tica, ejecuta el c&amp;#243;digo en paralelo, mandando cada n&amp;#250;mero a un n&amp;#250;cleo del procesador, ahorrando mucho tiempo.&lt;/p&gt;
&lt;p&gt;Y, por supuesto, NumPy y SciPy tienen much&amp;#237;simas funciones muy potentes, como rutinas para integrar, interpolaciones, regresiones, funciones de Bessel, convoluciones, transformadas diversas&amp;#8230; Pr&amp;#225;cticamente toda la matem&amp;#225;tica gen&amp;#233;rica que uno puede necesitar.&lt;/p&gt;
&lt;p&gt;&amp;#191;C&amp;#243;mo funciona? Np y Sc son una gran interfaz para bibliotecas matem&amp;#225;ticas en C, por lo que, tu c&amp;#243;digo Python no hace m&amp;#225;s que llamar la ejecuci&amp;#243;n de c&amp;#243;digo C compilado.&lt;/p&gt;
&lt;h2&gt;&lt;/h2&gt;
&lt;h2&gt;Paralelizando: Numexpr&lt;/h2&gt;
&lt;p&gt;La paralelizaci&amp;#243;n es una buena forma de acelerar la ejecuci&amp;#243;n de un programa, siempre que sea suficientemente separable. El caso extremo son los problemas vergonzosamente paralelizables, en los que podemos dividir el espacio de par&amp;#225;metros a estudiar en suficientes compartimentos estancos. En este caso, la paralelizaci&amp;#243;n es tan f&amp;#225;cil como lanzar tantos programas como n&amp;#250;cleos tengamos, cada uno estudiando una parte. Ejemplo: colisiones de un acelerador de part&amp;#237;culas, cada evento es completamente independiente de los dem&amp;#225;s.&lt;/p&gt;
&lt;p&gt;Otras veces no tenemos tanta suerte y s&amp;#243;lo podemos paralelizar algunas partes de nuestro programa. Python ofrece los m&amp;#243;dulos &lt;em&gt;threading&lt;/em&gt; y &lt;em&gt;multiprocessing&lt;/em&gt;, pero su uso es m&amp;#225;s sutil y complicado de lo que quiero tratar en este art&amp;#237;culo.&lt;/p&gt;
&lt;p&gt;No obstante, no est&amp;#225; todo perdido. Si queremos aplicar funciones b&amp;#225;sicas sobre grandes conjuntos de n&amp;#250;meros y NumPy se nos queda corto, podemos usar &lt;a href=&quot;https://code.google.com/p/numexpr/&quot;&gt;Numexpr&lt;/a&gt;. Nuestro viejo c&amp;#243;digo quedar&amp;#237;a:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
# Implementaci&amp;#243;n con NumPy y Numexpr
import numpy as np
import numexpr as ne
numbers=np.range(10)

result=ne.evaluate('sqrt(numbers)+sin(numbers)') # N&amp;#243;tese que va como texto
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Numexpr tiene varias estrategias para acelerar el c&amp;#243;digo. En primer lugar, cuando NumPy ejecuta el c&amp;#243;digo, primero calcula las ra&amp;#237;ces y las guarda en memoria, despu&amp;#233;s los senos y los guarda en memoria, y por &amp;#250;ltimo, los suma ambos y guarda el resultado final en memoria. Esto supone triplicar la memoria necesaria, y por tanto, el tr&amp;#225;fico de datos entre la CPU y la RAM.&lt;/p&gt;
&lt;p&gt;Podemos ahorrar memoria haciendo la cuenta elemento a elemento,&amp;#160; calculando la ra&amp;#237;z y el seno del primero y sumarlos, etc. Esto fuerza a Python a comprobar qu&amp;#233; tipo de dato es en cada momento para saber c&amp;#243;mo hacer la cuenta, y esto ha de hacerse cada vez. Numexpr, en cambio, divide la operaci&amp;#243;n en trozos manejables, que no castiguen mucho la memoria, y que eviten comprobaciones redundantes.&lt;/p&gt;
&lt;p&gt;Adem&amp;#225;s, incluye su propio compilador JIT, que genera c&amp;#243;digo muy eficiente, y adem&amp;#225;s intenta usar varios n&amp;#250;cleos all&amp;#237; donde NumPy no sabe. Para tama&amp;#241;os suficientemente grandes de datos, podemos llegar a alcanzar la velocidad l&amp;#237;mite que da la memoria del ordenador, &amp;#161;y sin haber escrito una sola l&amp;#237;nea fuera de Python!&lt;/p&gt;
&lt;h1&gt;Magia arcana:&lt;em&gt; blitz&lt;/em&gt;&lt;/h1&gt;
&lt;p&gt;Llegamos a un problema en el que nada de lo anterior ha sido suficiente, sigue siendo demasiado lento. En realidad, sabemos que la causa son s&amp;#243;lo unas pocas l&amp;#237;neas de c&amp;#243;digo&amp;#8230; es la hora de la magia misteriosa.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;weave&lt;/em&gt; es un m&amp;#243;dulo dentro de NumPy para comunicar Python y C. Una de sus funciones es &lt;em&gt;&lt;a href=&quot;http://www.scipy.org/PerformancePython#head-cafc55bbf8fd74071b2c2ebcfb6f24ed1989d540&quot;&gt;blitz&lt;/a&gt;&lt;/em&gt;, que toma una l&amp;#237;nea de Python, la traduce de forma transparente a C, y cada vez que la llames se ejecutar&amp;#225; esta versi&amp;#243;n optimizada. En hacer esta primera conversi&amp;#243;n necesita entorno a un segundo, pero consigue velocidades generalmente superiores a todas las opciones anteriores. Ya no es &lt;em&gt;bytecode&lt;/em&gt; como Numexpr o Psyco, o una interfaz a C como NumPy, sino tu propia funci&amp;#243;n escrita directamente en C y completamente compilada y optimizada.&lt;/p&gt;
&lt;p&gt;Nota: aunque en Linux y Mac funciona seg&amp;#250;n se instala, en Windows no he sido capaz de hacerlo funcionar nunca.&lt;/p&gt;
&lt;h1&gt;Rindi&amp;#233;ndonos al compilador&lt;/h1&gt;
&lt;p&gt;Est&amp;#225; bien, vamos a compilar algo de c&amp;#243;digo.Una opci&amp;#243;n previa es&lt;a href=&quot;http://cython.org/&quot;&gt; Cython&lt;/a&gt;, una versi&amp;#243;n del lenguaje Python con declaraci&amp;#243;n de variables opcional (pero recomendada) que puede ser compilada a c&amp;#243;digo C y luego llamado desde Python. La gran ventaja es que este c&amp;#243;digo es plenamente funcional dentro de Python, incluso antes del compilado. Adem&amp;#225;s, soporta arrays de NumPy. Sin embargo, est&amp;#225; limitado a tipos est&amp;#225;ticos y el proceso de generar el c&amp;#243;digo es un tanto complejo/pesado.&lt;/p&gt;
&lt;p&gt;Otro proyecto interesante es &lt;a href=&quot;http://shed-skin.blogspot.com.es/&quot;&gt;Shedskin&lt;/a&gt;. En este caso, toma c&amp;#243;digo Python puro (con algunas restricciones, como el tipado est&amp;#225;tico) y genera c&amp;#243;digo C++ (ilegible, pero funcional) optimizado. El proyecto parece ser llevado por una sola persona, y va lento, pero el resultado promete interesante y m&amp;#225;s sencillo que Cython. Como principal desventaja es que no soporta estructuras de NumPy o similares.&lt;/p&gt;
&lt;p&gt;Podemos seguir aprovechando&lt;em&gt; weave&lt;/em&gt; a trav&amp;#233;s de su funci&amp;#243;n &lt;a href=&quot;http://www.scipy.org/PerformancePython#head-a3f4dd816378d3ba4cbdd3d23dc98529e8ad7087&quot;&gt;&lt;em&gt;inline&lt;/em&gt;&lt;/a&gt;.&amp;#160; &amp;#201;sta toma como argumento c&amp;#243;digo C dentro del programa Python. Al igual que blitz, la primera ejecuci&amp;#243;n es la m&amp;#225;s lenta, pues tiene que compilarlo, pero las siguientes son mucho m&amp;#225;s r&amp;#225;pidas. Su principal inconveniente es que requiere &lt;em&gt;escribir&lt;/em&gt; c&amp;#243;digo en otro lenguaje&amp;#8230; a menos que uses lo que te ha dado Shedskin, por ejemplo. Tambi&amp;#233;n puede ser usado como m&amp;#233;todo de inserci&amp;#243;n de piezas sencillas de c&amp;#243;digo de un colaborador.&lt;/p&gt;
&lt;p&gt;Por &amp;#250;ltimo, los de la vieja escuela quiz&amp;#225; gusten de &lt;a href=&quot;http://www.scipy.org/F2py&quot;&gt;F2py&lt;/a&gt; para llamar a c&amp;#243;digo Fortran desde Python.&lt;/p&gt;
&lt;h1&gt;El futuro: PyPy.&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;http://pypy.org/&quot;&gt;PyPy&lt;/a&gt; es un int&amp;#233;rprete de Python&amp;#8230; escrito en Python. Usando un lenguaje de mucho m&amp;#225;s alto nivel son capaces de optimizar ese mismo lenguaje. Es un gran proyecto a&amp;#250;n en desarrollo, en el que se est&amp;#225; invirtiendo mucho esfuerzo, pero que ha obtenido algunos &lt;a href=&quot;http://speed.pypy.org/&quot;&gt;resultados impresionantes&lt;/a&gt;. &amp;#161;En un &lt;em&gt;benchmark&lt;/em&gt; se llega a una aceleraci&amp;#243;n del 98%!&lt;/p&gt;
&lt;p&gt;No es una opci&amp;#243;n todav&amp;#237;a porque todav&amp;#237;a le faltan muchas cosas, como soporte para bibliotecas externas como NumPy, aunque estamos &lt;a href=&quot;http://morepypy.blogspot.com.es/2012/04/numpy-on-pypy-progress-report.html&quot;&gt;cerca&lt;/a&gt;. Ignoro si hay alg&amp;#250;n problema m&amp;#225;s all&amp;#225; de las bibliotecas.&lt;/p&gt;
&lt;br /&gt;Filed under: &lt;a href=&quot;http://pybonacci.wordpress.com/category/basico/&quot;&gt;B&amp;#225;sico&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/category/intermedio/&quot;&gt;Intermedio&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/category/optimizacion-2/&quot;&gt;Optimizaci&amp;#243;n&lt;/a&gt;  &lt;a href=&quot;http://feeds.wordpress.com/1.0/gocomments/pybonacci.wordpress.com/348/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/comments/pybonacci.wordpress.com/348/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godelicious/pybonacci.wordpress.com/348/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/delicious/pybonacci.wordpress.com/348/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gofacebook/pybonacci.wordpress.com/348/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/facebook/pybonacci.wordpress.com/348/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gotwitter/pybonacci.wordpress.com/348/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/twitter/pybonacci.wordpress.com/348/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gostumble/pybonacci.wordpress.com/348/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/stumble/pybonacci.wordpress.com/348/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godigg/pybonacci.wordpress.com/348/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/digg/pybonacci.wordpress.com/348/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/goreddit/pybonacci.wordpress.com/348/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/reddit/pybonacci.wordpress.com/348/&quot; /&gt;&lt;/a&gt; &lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://stats.wordpress.com/b.gif?host=pybonacci.wordpress.com&amp;#038;blog=33759577&amp;#038;post=348&amp;#038;subd=pybonacci&amp;#038;ref=&amp;#038;feed=1&quot; width=&quot;1&quot; /&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://pybonacci.wordpress.com/?p=335
            </guid>
            <title>
                Pybonacci: C&amp;#243;mo calcular l&amp;#237;mites, derivadas, series e integrales en Python con SymPy
            </title>
            <pubDate>
                Mon, 30 Apr 2012 15:19:27 GMT
            </pubDate>
            <link>
                http://pybonacci.wordpress.com/2012/04/30/como-calcular-limites-derivadas-series-e-integrales-en-python-con-sympy/
            </link>
            <description>
                &lt;h2&gt;Introducci&amp;#243;n&lt;/h2&gt;
&lt;p&gt;Como buen paquete de c&amp;#225;lculo simb&amp;#243;lico que es, Sympy ofrece numerosas posibilidades para realizar tareas comunes del c&amp;#225;lculo infinitesimal, como son&amp;#160;calcular &lt;strong&gt;l&amp;#237;mites, derivadas, series e integrales&amp;#160;simb&amp;#243;licas&lt;/strong&gt;. Por ejemplo, mientras que con SciPy podemos calcular, utilizando &lt;a href=&quot;http://es.wikipedia.org/wiki/Derivaci%C3%B3n_num%C3%A9rica&quot;&gt;diferencias centradas&lt;/a&gt;, la derivada de una funci&amp;#243;n en un punto utilizando la funci&amp;#243;n &lt;code&gt;&lt;a href=&quot;http://docs.scipy.org/doc/scipy/reference/generated/scipy.misc.derivative.html&quot;&gt;scipy.misc.derivative&lt;/a&gt;&lt;/code&gt;, con SymPy podemos&amp;#160;&lt;strong&gt;calcular la derivada simb&amp;#243;lica&lt;/strong&gt; de la funci&amp;#243;n.&lt;/p&gt;
&lt;p&gt;Si no conoces SymPy, puedes leer nuestra &lt;a href=&quot;http://pybonacci.wordpress.com/2012/04/04/introduccion-al-calculo-simbolico-en-python-con-sympy/&quot;&gt;Introducci&amp;#243;n al C&amp;#225;lculo Simb&amp;#243;lico en Python con&amp;#160;SymPy&lt;/a&gt;&amp;#160;para hacerte una idea del manejo del paquete. Este art&amp;#237;culo est&amp;#225; basado en la &lt;a href=&quot;http://docs.sympy.org/0.7.1/tutorial.html#calculus&quot;&gt;secci&amp;#243;n de C&amp;#225;lculo Infinitesimal del tutorial de SymPy&lt;/a&gt;, y en &amp;#233;l utilizaremos el int&amp;#233;rprete interactivo de SymPy (&lt;code&gt;isympy&lt;/code&gt;) que viene incluido con el paquete; para que el c&amp;#243;digo funcione en un programa Python normal, s&amp;#243;lo habr&amp;#237;a que incluir las correspondientes sentencias &lt;code&gt;import&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;span id=&quot;more-335&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;En esta entrada se ha usado&amp;#160;python2 2.7.3 y&amp;#160;sympy 0.7.1.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;L&amp;#237;mites&lt;/h2&gt;
&lt;p&gt;Para calcular l&amp;#237;mites simb&amp;#243;licos con SymPy se utiliza la funci&amp;#243;n &lt;code&gt;&lt;a href=&quot;http://docs.sympy.org/0.7.1/modules/series.html#sympy.series.limits.limit&quot;&gt;limit&lt;/a&gt;&lt;/code&gt;. Podemos calcular el l&amp;#237;mite de casi cualquier expresi&amp;#243;n&amp;#160;[&lt;a href=&quot;http://pybonacci.wordpress.com/feed/#cite_note-0&quot; id=&quot;cite_ref-0&quot;&gt;1&lt;/a&gt;], con una o varias variables y por las dos direcciones:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [1]: limit?
Type: &amp;#160; &amp;#160; &amp;#160; function
Base Class: &amp;lt;type 'function'&amp;gt;
String Form:
Namespace: &amp;#160;Interactive
File: &amp;#160; &amp;#160; &amp;#160; /usr/lib/python2.7/site-packages/sympy/series/limits.py
Definition: limit(e, z, z0, dir='+')
Docstring:
Compute the limit of e(z) at the point z0.
[...]

In [2]: limit(1 / x, x, oo)
Out[2]: 0

In [3]: limit(sin(x) / x, x, 0)
Out[3]: 1

In [4]: limit(1 / sin(x), x, 0)
Out[4]: &amp;#8734;

In [5]: limit(1 / (x ** 2 + y ** 2), x, 0)
Out[5]:
1
&amp;#9472;&amp;#9472;
 2
y

In [6]: limit(tan(x), x, pi / 2)
Out[6]: -&amp;#8734;

In [7]: limit(tan(x), x, pi / 2, dir='+')
Out[7]: -&amp;#8734;

In [8]: limit(tan(x), x, pi / 2, dir='-')
Out[8]: &amp;#8734;

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Como indican en la documentaci&amp;#243;n de la funci&amp;#243;n, hay bastantes ejemplos de l&amp;#237;mites no triviales en el archivo &lt;a href=&quot;https://github.com/sympy/sympy/blob/master/sympy/series/tests/test_demidovich.py&quot;&gt;&lt;code&gt;https://github.com/sympy/sympy/blob/master/sympy/series/tests/test_demidovich.py&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Derivadas&lt;/h2&gt;
&lt;p&gt;Para calcular la derivada simb&amp;#243;lica en SymPy (esto es: la funci&amp;#243;n derivada) se usa la funci&amp;#243;n &lt;a href=&quot;http://docs.sympy.org/0.7.1/modules/core.html#sympy.core.function.diff&quot;&gt;&lt;code&gt;diff&lt;/code&gt;&lt;/a&gt; o el m&amp;#233;todo &lt;code&gt;.diff&lt;/code&gt; de una expresi&amp;#243;n. Esta admite varias sintaxis para indicar las variables y el orden de las derivadas:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [1]: cos(x) * (1 + x)
Out[1]: (x + 1)&amp;#8901;cos(x)

In [2]: diff(_1, x)  # Derivada primera con respecto a x
Out[2]: -(x + 1)&amp;#8901;sin(x) + cos(x)

In [3]: diff(_, x)  # Derivada primera con respecto a x de lo anterior
Out[3]: -(x + 1)&amp;#8901;cos(x) - 2&amp;#8901;sin(x)

In [4]: diff(_1, x, 2)  # Derivada segunda con respecto a x
Out[4]: -(x + 1)&amp;#8901;cos(x) - 2&amp;#8901;sin(x)

In [5]: diff(_1, x, x)  # Otra forma de escribir lo mismo
Out[5]: -(x + 1)&amp;#8901;cos(x) - 2&amp;#8901;sin(x)

In [6]: diff(log(x * y), y)  # Derivada parcial con respecto a y
Out[6]: 
1
&amp;#9472;
y

In [7]: diff(x * y * log(x * y), x, y)  # Derivada parcial con respecto a x e y
Out[7]: log(x&amp;#8901;y) + 2

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Tambi&amp;#233;n se pueden derivar funciones simb&amp;#243;licas, y se respeta la regla de la cadena:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [8]: diff(f(x) * sin(x), x)
Out[8]: 
                     d       
f(x)&amp;#8901;cos(x) + sin(x)&amp;#8901;&amp;#9472;&amp;#9472;(f(x))
                     dx   

In [9]: diff(f(g(x)), x)
Out[9]: 
d        &amp;#9115; d        &amp;#9118;&amp;#9474;       
&amp;#9472;&amp;#9472;(g(x))&amp;#8901;&amp;#9116;&amp;#9472;&amp;#9472;&amp;#9472;(f(&amp;#958;&amp;#8321;))&amp;#9119;&amp;#9474;       
dx       &amp;#9117;d&amp;#958;&amp;#8321;       &amp;#9120;&amp;#9474;&amp;#958;&amp;#8321;=g(x)   

In [10]: diff(f(x * y), y)
Out[10]: 
  &amp;#9115; d        &amp;#9118;&amp;#9474;      
x&amp;#8901;&amp;#9116;&amp;#9472;&amp;#9472;&amp;#9472;(f(&amp;#958;&amp;#8321;))&amp;#9119;&amp;#9474;      
  &amp;#9117;d&amp;#958;&amp;#8321;       &amp;#9120;&amp;#9474;&amp;#958;&amp;#8321;=x&amp;#8901;y

In [11]: diff(exp(f(x)), x, 2)
Out[11]: 
              2           2      
 f(x) d            f(x)  d       
&amp;#8495;    &amp;#8901;&amp;#9472;&amp;#9472;(f(x))  + &amp;#8495;    &amp;#8901;&amp;#9472;&amp;#9472;&amp;#9472;(f(x))
      dx                  2      
                        dx       

In [12]: diff(f(x), x, 3)
Out[12]: 
  3      
 d       
&amp;#9472;&amp;#9472;&amp;#9472;(f(x))
  3      
dx   

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Tambi&amp;#233;n, &lt;a href=&quot;http://pybonacci.wordpress.com/2012/04/04/introduccion-al-calculo-simbolico-en-python-con-sympy/#sustitucion&quot;&gt;utilizando sustituci&amp;#243;n como ya vimos en nuestra introducci&amp;#243;n&lt;/a&gt;, podemos calcular la derivada en un punto o dejar la derivada sin efectuar utilizando el argumento &lt;code&gt;evaluate&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;

In [13]: diff(sin(x) ** 2, x)
Out[13]: 2&amp;#8901;sin(x)&amp;#8901;cos(x)

In [14]: diff(sin(x) ** 2, x).subs(x, pi / 4)
Out[14]: 1

In [15]: diff(tan(x), x)
Out[15]: 
   2       
tan (x) + 1

In [16]: _.subs(x, pi / 6)
Out[16]: 4/3

In [17]: diff(cos(x), x, evaluate=False)
Out[17]: 
d         
&amp;#9472;&amp;#9472;(cos(x))
dx  
&lt;/pre&gt;&lt;/p&gt;
&lt;h2&gt;Series&lt;/h2&gt;
&lt;p&gt;Para calcular desarrollos en series de potencias en SymPy utilizamos la funci&amp;#243;n &lt;code&gt;series&lt;/code&gt; o el m&amp;#233;todo &lt;a href=&quot;http://docs.sympy.org/0.7.1/modules/core.html#sympy.core.expr.Expr.series&quot;&gt;&lt;code&gt;.series&lt;/code&gt;&lt;/a&gt; de una expresi&amp;#243;n [&lt;a href=&quot;http://pybonacci.wordpress.com/feed/#cite_note-1&quot; id=&quot;cite_ref-1&quot;&gt;2&lt;/a&gt;].&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [1]: Expr.series?
Type:       instancemethod
Base Class: &amp;lt;type 'instancemethod'&amp;gt;
String Form:&amp;lt;unbound method Expr.series&amp;gt;
Namespace:  Interactive
File:       /usr/lib/python2.7/site-packages/sympy/core/expr.py
Definition: Expr.series(self, x=None, x0=0, n=6, dir='+')
Docstring:
Series expansion of &amp;quot;self&amp;quot; around ``x = x0`` yielding either terms of
the series one by one (the lazy series given when n=None), else
all the terms at once when n != None.
[...]

In [2]: cos(x).series(x)  # Por defecto, desarrollo en torno al 0 con n = 6 t&amp;#233;rminos
Out[2]: 
     2    4          
    x    x           
1 - &amp;#9472;&amp;#9472; + &amp;#9472;&amp;#9472; + O(x**6)
    2    24          

In [3]: log(1 + x).series(x, 0, n=5)
Out[3]: 
     2    3    4          
    x    x    x           
x - &amp;#9472;&amp;#9472; + &amp;#9472;&amp;#9472; - &amp;#9472;&amp;#9472; + O(x**5)
    2    3    4           

In [4]: log(z).series(z, 1, n=5)  # Desarrollo en torno a z = 1 (n&amp;#243;tese que en la salida z es (z - 1))
Out[4]: 
     2    3    4          
    z    z    z           
z - &amp;#9472;&amp;#9472; + &amp;#9472;&amp;#9472; - &amp;#9472;&amp;#9472; + O(z**5)
    2    3    4  

In [5]: abs(x).series(x, 0, dir='+')  # Desarrollo por la derecha
Out[5]: x

In [6]: abs(x).series(x, 0, dir='-')  # Y por la izquierda
Out[6]: -x

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;SymPy ofrece otros dos m&amp;#233;todos relacionados con el c&amp;#225;lculo de series interesantes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;El m&amp;#233;todo &lt;a href=&quot;http://docs.sympy.org/0.7.1/modules/core.html#sympy.core.expr.Expr.nseries&quot;&gt;&lt;code&gt;.nseries&lt;/code&gt;&lt;/a&gt;. Calcula el desarrollo de una expresi&amp;#243;n de una manera distinta. Mientras que &lt;code&gt;.series&lt;/code&gt; nos da el n&amp;#250;mero de t&amp;#233;rminos que hemos indicado con el argumento &lt;code&gt;n&lt;/code&gt;, &lt;code&gt;.nseries&lt;/code&gt; calcula los desarrollos de los diferentes factores con ese n&amp;#250;mero de t&amp;#233;rminos y luego opera con ellos, de tal forma que el resultado final puede no llegar al orden que pretend&amp;#237;amos conseguir. En cambio, es un m&amp;#233;todo m&amp;#225;s r&amp;#225;pido porque no requiere saber a priori el n&amp;#250;mero de t&amp;#233;rminos necesarios:
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [7]: (sin(x) / x).series(x, n=3)
Out[7]: 
     2          
    x           
1 - &amp;#9472;&amp;#9472; + O(x**3)
    6           

In [8]: (sin(x) / x).nseries(x, n=3)  # El resultado sigue siendo correcto
Out[8]: 1 + O(x**2)
&lt;/pre&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;El m&amp;#233;todo &lt;a href=&quot;http://docs.sympy.org/0.7.1/modules/core.html#sympy.core.expr.Expr.lseries&quot;&gt;&lt;code&gt;.lseries&lt;/code&gt;&lt;/a&gt; proporciona un iterador con los t&amp;#233;rminos del desarrollo (es equivalente a llamar a &lt;code&gt;.series&lt;/code&gt; con &lt;code&gt;n=None&lt;/code&gt;:
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [9]: s = cos(x).lseries(x)

In [10]: for term in s:
   ....:     pprint(term)
   ....:     
1
  2
-x 
&amp;#9472;&amp;#9472;&amp;#9472;
 2 
 4
x 
&amp;#9472;&amp;#9472;
24
  6
-x 
&amp;#9472;&amp;#9472;&amp;#9472;
720
^C---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
[...]

In [11]: s = cos(x).series(x, n=None)  # Equivalente a lo anterior

In [12]: type(s)
Out[12]: generator

In [13]: s.next()
Out[13]: 1

In [14]: s.next()
Out[14]: 
  2
-x 
&amp;#9472;&amp;#9472;&amp;#9472;
 2 

In [15]: s.next()
Out[15]: 
 4
x 
&amp;#9472;&amp;#9472;
24

&lt;/pre&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Integrales&lt;/h2&gt;
&lt;p&gt;Para calcular integrales definidas e indefinidas con SymPy emplearemos la funci&amp;#243;n &lt;a href=&quot;http://docs.sympy.org/0.7.1/modules/integrals.html#sympy.integrals.integrate&quot;&gt;&lt;code&gt;integrate&lt;/code&gt;&lt;/a&gt;. Esta utiliza el &lt;a href=&quot;http://es.wikipedia.org/wiki/Algoritmo_de_Risch&quot;&gt;algoritmo de Risch-Norman extendido&lt;/a&gt; m&amp;#225;s algunas reglas heur&amp;#237;sticas y b&amp;#250;squeda de patrones:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [1]: integrate(6 * x ** 5, x)
Out[1]: 
 6
x 

In [2]: integrate(x * log(x), x)
Out[2]: 
 2           2
x &amp;#8901;log(x)   x 
&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472; - &amp;#9472;&amp;#9472;
    2       4 

In [3]: integrate(exp(-x ** 2), x)
Out[3]: 
  &amp;#9149;&amp;#9149;&amp;#9149;       
&amp;#9586;&amp;#9585; &amp;#960; &amp;#8901;erf(x)
&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;
     2      

In [4]: integrate(x * y, y)
Out[4]: 
   2
x&amp;#8901;y 
&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;
 2  

In [5]: integrate(cos(x), y)
Out[5]: y&amp;#8901;cos(x)

In [6]: integrate(x * y, x, y)
Out[6]: 
 2  2
x &amp;#8901;y 
&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;
  4  

In [7]: integrate(x, x, x, y)
Out[7]: 
 3  
x &amp;#8901;y
&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;
 6 

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Tambi&amp;#233;n podemos efectuar integrales definidas, tanto propias como impropias:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [8]: integrate(log(x), (x, 0, 1))
Out[8]: -1

In [9]: integrate(sin(x) ** 2, (x, 0, pi))
Out[9]: 
&amp;#960;
&amp;#9472;
2

In [10]: integrate(sin(x), (x, 0, oo))
Out[10]: 1 - cos(&amp;#8734;)

In [11]: integrate(exp(-x ** 2), (x, 0, oo))
Out[11]: 
  &amp;#9149;&amp;#9149;&amp;#9149;
&amp;#9586;&amp;#9585; &amp;#960; 
&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;
  2  

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Y hasta aqu&amp;#237; el art&amp;#237;culo de hoy. Si te ha resultado &amp;#250;til o interesante (que espero que s&amp;#237;), recuerda comentar y difundir.&lt;/p&gt;
&lt;p&gt;&amp;#161;Un saludo!&lt;/p&gt;
&lt;h2&gt;Notas&lt;/h2&gt;
&lt;ol&gt;
&lt;li id=&quot;cite_note-0&quot;&gt;[&lt;a href=&quot;http://pybonacci.wordpress.com/feed/#cite_ref-0&quot;&gt;^&lt;/a&gt;]&amp;#160;SymPy utiliza el&amp;#160;&lt;a href=&quot;http://docs.sympy.org/0.7.1/modules/series.html#the-gruntz-algorithm&quot;&gt;algoritmo de Gruntz&lt;/a&gt;&amp;#160;para calcular l&amp;#237;mites y requiere evaluar la serie de las funciones, por lo que los l&amp;#237;mites no pueden involucrar funciones definidas por el usuario (v&amp;#233;ase [&lt;a href=&quot;http://pybonacci.wordpress.com/feed/#cite_note-1&quot; id=&quot;cite_ref-1&quot;&gt;2&lt;/a&gt;]).&lt;/li&gt;
&lt;li id=&quot;cite_note-1&quot;&gt;[&lt;a href=&quot;http://pybonacci.wordpress.com/feed/#cite_ref-1&quot;&gt;^&lt;/a&gt;]&amp;#160;Las series para funciones definidas por el usuario&amp;#160;&lt;a href=&quot;https://github.com/sympy/sympy/blob/sympy-0.7.1/sympy/core/function.py#L336&quot;&gt;no est&amp;#225;n soportadas todav&amp;#237;a&lt;/a&gt;&amp;#160;en la versi&amp;#243;n 0.7.1.&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;Filed under: &lt;a href=&quot;http://pybonacci.wordpress.com/category/basico/&quot;&gt;B&amp;#225;sico&lt;/a&gt; Tagged: &lt;a href=&quot;http://pybonacci.wordpress.com/tag/calculo-simbolico/&quot;&gt;c&amp;#225;lculo simb&amp;#243;lico&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/derivadas/&quot;&gt;derivadas&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/integrales/&quot;&gt;integrales&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/limites/&quot;&gt;l&amp;#237;mites&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/python/&quot;&gt;python&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/series/&quot;&gt;series&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/sympy/&quot;&gt;sympy&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gocomments/pybonacci.wordpress.com/335/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/comments/pybonacci.wordpress.com/335/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godelicious/pybonacci.wordpress.com/335/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/delicious/pybonacci.wordpress.com/335/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gofacebook/pybonacci.wordpress.com/335/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/facebook/pybonacci.wordpress.com/335/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gotwitter/pybonacci.wordpress.com/335/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/twitter/pybonacci.wordpress.com/335/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gostumble/pybonacci.wordpress.com/335/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/stumble/pybonacci.wordpress.com/335/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godigg/pybonacci.wordpress.com/335/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/digg/pybonacci.wordpress.com/335/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/goreddit/pybonacci.wordpress.com/335/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/reddit/pybonacci.wordpress.com/335/&quot; /&gt;&lt;/a&gt; &lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://stats.wordpress.com/b.gif?host=pybonacci.wordpress.com&amp;#038;blog=33759577&amp;#038;post=335&amp;#038;subd=pybonacci&amp;#038;ref=&amp;#038;feed=1&quot; width=&quot;1&quot; /&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://python.majibu.org/preguntas/1483/streaming-de-audio-en-tiempo-real
            </guid>
            <title>
                python majibu: Streaming de audio en tiempo real
            </title>
            <pubDate>
                Sun, 29 Apr 2012 07:10:03 GMT
            </pubDate>
            <link>
                http://python.majibu.org/preguntas/1483/streaming-de-audio-en-tiempo-real
            </link>
            <description>
                &lt;p&gt;Alguien sabe como realizar streaming de audio en tiempo real con python ya sea usando las librerias de gstreamer o pygame ?&lt;/p&gt;
&lt;p&gt;de antemano muchas gracias&lt;/p&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://python.majibu.org/preguntas/1470/descargar-ficheros-en-django
            </guid>
            <title>
                python majibu: Descargar ficheros en Django
            </title>
            <pubDate>
                Sat, 28 Apr 2012 14:24:06 GMT
            </pubDate>
            <link>
                http://python.majibu.org/preguntas/1470/descargar-ficheros-en-django
            </link>
            <description>
                &lt;p&gt;Como descargar ficheros en Django.&lt;/p&gt;
&lt;p&gt;He escrito la siguiente vista:&lt;/p&gt;
&lt;table class=&quot;codehilitetable&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;linenos&quot;&gt;&lt;div class=&quot;linenodiv&quot;&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;descarga2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# Create the HttpResponse object with the appropriate PDF headers.&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HttpResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mimetype&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'application/pdf'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Content-Disposition'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'attachment; filename=ARONA.pdf'&lt;/span&gt;

    &lt;span class=&quot;c&quot;&gt;# Create the PDF object, using the response object as its &quot;file.&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fichero&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'.&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;images&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ARONA.pdf'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'rb'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fichero&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Pero aunque aparentemente funciona el objeto que te descargas est&amp;#225; vac&amp;#237;o, no hay nada.&lt;/p&gt;
&lt;p&gt;Como alternativas he visto las siguientes:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://docs.djangoproject.com/en/dev/howto/outputting-pdf/?from=olddocs&quot;&gt;Esta&lt;/a&gt;&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;El problema que tiene es que no env&amp;#237;as el pdf existente en el sistema, sino que env&amp;#237;a un objeto que creas sobre la marcha, puede que sea la soluci&amp;#243;n para lo que necesito, pero aun no lo tengo claro del todo.&lt;/p&gt;
&lt;p&gt;y &lt;strong&gt;&lt;a href=&quot;http://djangosnippets.org/snippets/365/&quot;&gt;esta: &lt;/a&gt;&lt;/strong&gt; &lt;/p&gt;
&lt;p&gt;En este caso pasa algo parecido, envia ficheros sobre la marcha y he intentado modificarlo para que me funcione y no me rula ...&lt;/p&gt;
&lt;p&gt;El tema es que no se porque la vista que les he puesto arriba no me funciona, ya que no tira ning&amp;#250;n error pero el objeto que envia est&amp;#225; vac&amp;#237;o.&lt;/p&gt;
&lt;p&gt;Gracias y saludos.!!&lt;/p&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://python.majibu.org/preguntas/1465/es-correcto-agregar-atributos-a-una-clase-de-modelo-en-tiempo-de-ejecucion
            </guid>
            <title>
                python majibu: &amp;#191;Es correcto agregar atributos a una clase de modelo en tiempo de ejecuci&amp;#243;n?
            </title>
            <pubDate>
                Fri, 27 Apr 2012 20:56:01 GMT
            </pubDate>
            <link>
                http://python.majibu.org/preguntas/1465/es-correcto-agregar-atributos-a-una-clase-de-modelo-en-tiempo-de-ejecucion
            </link>
            <description>
                &lt;p&gt;Hola comunidad!!!&lt;/p&gt;
&lt;p&gt;Tengo un blog en Blogger, de &lt;a href=&quot;http://pensamientos-schcriher.blogspot.com/&quot;&gt;Pensamientos&lt;/a&gt;, el cual lo estoy pasando a una pagina personal creada en Django (estoy usando Django 1.4). Para almacenar la informaci&amp;#243;n, en varios idiomas, he creado 4 modelos, dos para los pensamientos y dos para las etiquetas. Les pongo una versi&amp;#243;n reducida del models.py (le saque atributos para traducci&amp;#243;n de texto, algunos unique=True y valores por defecto)&lt;/p&gt;
&lt;table class=&quot;codehilitetable&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;linenos&quot;&gt;&lt;div class=&quot;linenodiv&quot;&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Etiquetas&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;numero&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AutoField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;primary_key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TEtiquetas&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;texto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CharField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;explicacion&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TextField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;idioma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CharField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;choices&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;settings&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LANGUAGES&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;eid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ForeignKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Etiquetas&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;related_name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'traducciones'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Pensamientos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;numero&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AutoField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;primary_key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fecha&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DateTimeField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;mostrar_pensamiento&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BooleanField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;etiquetas&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ManyToManyField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Etiquetas&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;related_name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'pensamientos'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TPensamientos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;texto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TextField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;explicacion&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TextField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;idioma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CharField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;choices&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;settings&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LANGUAGES&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;mostrar_pensamiento&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BooleanField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;mostrar_comentarios&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BooleanField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;habilitar_comentarios&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BooleanField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;pid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ForeignKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Pensamientos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;related_name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'traducciones'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;La idea es as&amp;#237;: para un pensamiento determinado, se crea un objeto Pensamientos, y luego se crean objetos TPensamientos con los contenidos en los distintos idioma. Lo mismo para las etiquetas. 
En el views.py, tengo lo siguiente:&lt;/p&gt;
&lt;table class=&quot;codehilitetable&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;linenos&quot;&gt;&lt;div class=&quot;linenodiv&quot;&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PensamientosListView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ListView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;context_object_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'PENSAMIENTOS'&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;template_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'lista.html'&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;paginate_by&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'pensamientos_por_pagina'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;get_queryset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;filtros&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;'idioma__istartswith'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;REGEX_SEPARADOR&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_language&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;'mostrar_pensamiento'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;'pid__mostrar_pensamiento'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'etiqueta'&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kwargs:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kwargs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'etiqueta'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;filtros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;update&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
                &lt;span class=&quot;s&quot;&gt;'pid__etiquetas__traducciones__texto__iexact'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;get_list_or_404&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TPensamientos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;filtros&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;get_context_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kwargs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PensamientosListView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_context_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kwargs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pensamiento&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'PENSAMIENTOS'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;etiquetas&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TEtiquetas&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;objects&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;eid__pensamientos__traducciones&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pensamiento&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;idioma__istartswith&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pensamiento&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;idioma&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;pensamiento&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;etiquetas&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;etiqueta&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;texto&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;etiqueta&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;etiquetas&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;As&amp;#237; funciona sin problemas aparentemente o al menos no los detecte todav&amp;#237;a. Esa ultima parte de la vista es para tener disponible las etiquetas en la plantilla para mostrarlas. Ya que la relaci&amp;#243;n es un ManyToMany debo filtrarlo antes de ir a la plantilla. Se me acaba de ocurrir que ese trabajo lo podr&amp;#237;a delegar a un filtro en la plantilla (igual me queda esta duda).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;La pregunta es&lt;/strong&gt;: esta bien agregar el atributo &lt;em&gt;etiquetas&lt;/em&gt; al objeto &lt;em&gt;pensamiento&lt;/em&gt; de la clase &lt;em&gt;TPensamientos&lt;/em&gt; (en el m&amp;#233;todo &lt;em&gt;get_context_data&lt;/em&gt; de &lt;em&gt;PensamientosListView&lt;/em&gt;). Hab&amp;#237;a le&amp;#237;do en alguna parte de la documentaci&amp;#243;n oficial una advertencia relacionado a esto (seg&amp;#250;n recuerdo) pero no la encuentro. Entiende que las clases se inst&amp;#225;ncian una ves al arrancar el servidor por cuestiones de eficiencia, y mi duda es si eso no es un problema una ves que este en producci&amp;#243;n y m&amp;#250;ltiples usuarios acedan a la pagina.&lt;/p&gt;
&lt;p&gt;Les agradecer&amp;#233; cualquier comentario o referencia para aclarar esta duda, desde ya muchas gracias!&lt;/p&gt;
&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;EDITO&lt;/strong&gt;: Correg&amp;#237; un error en el m&amp;#233;todo &lt;em&gt;get_context_data&lt;/em&gt;&lt;/p&gt;
&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;EDITO 2&lt;/strong&gt;: Correg&amp;#237; el titulo, la clase modificada en tiempo de ejecuci&amp;#243;n es de &lt;em&gt;modelo&lt;/em&gt; y no de &lt;em&gt;vista&lt;/em&gt;.&lt;/p&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://lesthack.com.mx/?p=2193
            </guid>
            <title>
                codeplasticlesthack: FLISOL Celaya 2012: Pl&amp;#225;tica &amp;#8220;Python + WebKit&amp;#8221;
            </title>
            <pubDate>
                Fri, 27 Apr 2012 14:39:04 GMT
            </pubDate>
            <link>
                http://lesthack.com.mx/2012/04/27/flisol-celaya-2012-platica-python-webkit/
            </link>
            <description>
                &lt;div class=&quot;twoColumn&quot;&gt;
&lt;p style=&quot;text-align: center;&quot;&gt;
&lt;a href=&quot;http://flisol.abricolabs.net/index.php?title=Main_Page&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-2201&quot; height=&quot;599&quot; src=&quot;http://lesthack.com.mx/wp-content/uploads/2012/04/406px-Cartel_FLISoL_2012-Difusi&amp;#243;n.jpg&quot; title=&quot;406px-Cartel_FLISoL_2012-Difusi&amp;#243;n&quot; width=&quot;406&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;twoColumn&quot;&gt;
Es el &lt;a href=&quot;http://flisol.abricolabs.net/index.php?title=Main_Page&quot;&gt;4to a&amp;#241;o consecutivo&lt;/a&gt; que este evento se lleva a cabo en Celaya, &amp;#250;nica sede del estado de Guanajuato por desgracia. Evento que es realizado dentro del &lt;a href=&quot;http://www.itc.mx/&quot;&gt;Instituto Tecnol&amp;#243;gico de Celaya&lt;/a&gt; y en el que estuve involucrado en organizaci&amp;#243;n y coordinaci&amp;#243;n&lt;a href=&quot;http://lesthack.com.mx/category/flisol-2/&quot;&gt; durante 2 a&amp;#241;os (2009, 2010)&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Este a&amp;#241;o (&lt;a href=&quot;http://lesthack.com.mx/2011/04/16/flisol-celaya-2011/&quot;&gt;como el pasado&lt;/a&gt;) estuve de invitado para impartir una pl&amp;#225;tica, y en este caso, con la tem&amp;#225;tica de algunos experimentos que durante mis ratos libres (ya realmente son pocos) he estado probando con python y webkit.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.webkit.org/&quot;&gt;Webkit&lt;/a&gt; ya es considerada como una plataforma para aplicaciones, podemos embeberla sencillamente con python para transportar una aplicaci&amp;#243;n web a una aplicaci&amp;#243;n de escritorio, y aprovechar toda la tecnolog&amp;#237;a que Apple, Google y la comunidad ha venido desarrollando.&lt;/p&gt;
&lt;p&gt;Los a credos a &lt;a href=&quot;http://www.python.org/&quot;&gt;Python&lt;/a&gt; como yo, sabemos que este lenguaje es hermoso, pero mas all&amp;#225; de la est&amp;#233;tica en sintaxis, encontramos una infinidad de librear&amp;#237;as para casi todo, y es por ello que juega un papel importante. &lt;/p&gt;
&lt;p&gt;Dejo la presentaci&amp;#243;n para aquellos que quisieran darle una simple vista, y en breve subir&amp;#233; los pocos c&amp;#243;digos de ejemplo que present&amp;#233;.&lt;/p&gt;
&lt;p style=&quot;text-align: center;&quot;&gt;
&lt;a href=&quot;http://lesthack.com.mx/util/conferences/Platica%20-%20Python%20+%20Webkit.pdf&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-medium wp-image-2194&quot; height=&quot;225&quot; src=&quot;http://lesthack.com.mx/wp-content/uploads/2012/04/python-webkit-300x225.png&quot; title=&quot;python-webkit&quot; width=&quot;300&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;/div&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://pybonacci.wordpress.com/?p=246
            </guid>
            <title>
                Pybonacci: Regiones de estabilidad de m&amp;#233;todos num&amp;#233;ricos en Python
            </title>
            <pubDate>
                Fri, 27 Apr 2012 08:36:19 GMT
            </pubDate>
            <link>
                http://pybonacci.wordpress.com/2012/04/27/regiones-de-estabilidad-de-metodos-numericos-en-python/
            </link>
            <description>
                &lt;h2&gt;Introducci&amp;#243;n&lt;/h2&gt;
&lt;p&gt;Hoy veremos c&amp;#243;mo computar con Python la &lt;strong&gt;regi&amp;#243;n de estabilidad absoluta&lt;/strong&gt; de un m&amp;#233;todo num&amp;#233;rico para resolver problemas de valores iniciales en ecuaciones diferenciales ordinarias, una herramienta muy importante a la hora de escoger un m&amp;#233;todo num&amp;#233;rico adecuado para integrar nuestro problema concreto. Se trata simplemente de otro ejemplo aplicado de lo que publicamos hace unos d&amp;#237;as sobre &lt;a href=&quot;http://pybonacci.wordpress.com/2012/04/13/dibujando-lineas-de-nivel-en-python-con-matplotlib/&quot;&gt;c&amp;#243;mo pintar curvas de nivel con matplotlib&lt;/a&gt;; si quieres ver otro m&amp;#225;s, puedes leer nuestro &lt;a href=&quot;http://pybonacci.wordpress.com/2012/04/14/ejemplo-de-uso-de-basemap-y-netcdf4/&quot;&gt;ejemplo de uso de Basemap y NetCDF4&lt;/a&gt;, donde vimos c&amp;#243;mo representar datos climatol&amp;#243;gicos.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;En esta entrada se ha usado python 2.7.3, numpy 1.6.1 y matplotlib 1.1.0.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;span id=&quot;more-246&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;Regi&amp;#243;n de estabilidad absoluta&lt;/h2&gt;
&lt;p&gt;A la hora de integrar num&amp;#233;ricamente un problema diferencial del tipo&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&amp;#92;frac{d U}{d t} = A U&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%5Cfrac%7Bd+U%7D%7Bd+t%7D+%3D+A+U&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;&amp;#92;frac{d U}{d t} = A U&quot; /&gt;&lt;/p&gt;
&lt;p&gt;nos interesa que la soluci&amp;#243;n num&amp;#233;rica tenga el mismo car&amp;#225;cter de estabilidad que la soluci&amp;#243;n anal&amp;#237;tica y saber para qu&amp;#233; valores del paso de integraci&amp;#243;n podemos conseguir esto [Hern&amp;#225;ndez]. Mediante los autovalores &lt;img alt=&quot;&amp;#92;lambda&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%5Clambda&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;&amp;#92;lambda&quot; /&gt; de la matriz del sistema o los de la matriz jacobiana que resulta de linealizar el sistema [LeVeque], podemos definir la&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Regi&amp;#243;n de estabilidad absoluta&lt;/strong&gt;: regi&amp;#243;n del plano complejo &lt;img alt=&quot;&amp;#92;mathcal{R} &amp;#92;subset &amp;#92;mathbb{C}&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%5Cmathcal%7BR%7D+%5Csubset+%5Cmathbb%7BC%7D&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;&amp;#92;mathcal{R} &amp;#92;subset &amp;#92;mathbb{C}&quot; /&gt; tal que el m&amp;#233;todo es estable &lt;img alt=&quot;&amp;#92;forall &amp;#92;, &amp;#92;omega = &amp;#92;lambda &amp;#92;Delta t &amp;#92;in &amp;#92;mathcal{R}&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%5Cforall+%5C%2C+%5Comega+%3D+%5Clambda+%5CDelta+t+%5Cin+%5Cmathcal%7BR%7D&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;&amp;#92;forall &amp;#92;, &amp;#92;omega = &amp;#92;lambda &amp;#92;Delta t &amp;#92;in &amp;#92;mathcal{R}&quot; /&gt;.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Si la soluci&amp;#243;n de la ecuaci&amp;#243;n en diferencias resultante de discretizar el problema diferencial es de la forma&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;u^n = {&amp;#92;displaystyle &amp;#92;sum_k c_k r_k^n},&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=u%5En+%3D+%7B%5Cdisplaystyle+%5Csum_k+c_k+r_k%5En%7D%2C&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;u^n = {&amp;#92;displaystyle &amp;#92;sum_k c_k r_k^n},&quot; /&gt;&lt;/p&gt;
&lt;p&gt;entonces los &lt;img alt=&quot;r_k&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=r_k&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;r_k&quot; /&gt; deben ser ra&amp;#237;ces del&amp;#160;&lt;strong&gt;polinomio caracter&amp;#237;stico de estabilidad&lt;/strong&gt; del m&amp;#233;todo num&amp;#233;rico:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&amp;#92;pi(r) |_{&amp;#92;omega} = {&amp;#92;displaystyle &amp;#92;sum_{j = 0}^p (&amp;#92;alpha_j - &amp;#92;omega &amp;#92;beta_j) r^{p - j}}&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%5Cpi%28r%29+%7C_%7B%5Comega%7D+%3D+%7B%5Cdisplaystyle+%5Csum_%7Bj+%3D+0%7D%5Ep+%28%5Calpha_j+-+%5Comega+%5Cbeta_j%29+r%5E%7Bp+-+j%7D%7D&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;&amp;#92;pi(r) |_{&amp;#92;omega} = {&amp;#92;displaystyle &amp;#92;sum_{j = 0}^p (&amp;#92;alpha_j - &amp;#92;omega &amp;#92;beta_j) r^{p - j}}&quot; /&gt;&lt;/p&gt;
&lt;p&gt;que no depende del problema que estamos integrando. Si se cumple que el mayor de los valores absolutos de las ra&amp;#237;ces es menor o igual que 1 entonces la soluci&amp;#243;n num&amp;#233;rica ser&amp;#225; estable (asint&amp;#243;ticamente estable en el caso estrictamente menor), e inestable si hay alguna ra&amp;#237;z mayor que 1 en valor absoluto. Con esta informaci&amp;#243;n, vamos a computar la regi&amp;#243;n de estabilidad absoluta siguiendo el algoritmo que propone [Hern&amp;#225;ndez]:&lt;/p&gt;
&lt;h3&gt;Algoritmo&lt;/h3&gt;
&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;Discretizar una regi&amp;#243;n del plano complejo &lt;img alt=&quot;(x_i, y_j)&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%28x_i%2C+y_j%29&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;(x_i, y_j)&quot; /&gt;.&lt;/li&gt;
&lt;li&gt;Sea &lt;img alt=&quot;&amp;#92;rho&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%5Crho&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;&amp;#92;rho&quot; /&gt; una matriz. Para cada &lt;img alt=&quot;&amp;#92;omega_{ij} &amp;#92;leftarrow x_i + i y_j&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%5Comega_%7Bij%7D+%5Cleftarrow+x_i+%2B+i+y_j&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;&amp;#92;omega_{ij} &amp;#92;leftarrow x_i + i y_j&quot; /&gt;,
&lt;ol&gt;
&lt;li&gt;Obtener las ra&amp;#237;ces &lt;img alt=&quot;r_k &amp;#92;quad (k = 1, &amp;#92;, &amp;#92;dots, p)&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=r_k+%5Cquad+%28k+%3D+1%2C+%5C%2C+%5Cdots%2C+p%29&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;r_k &amp;#92;quad (k = 1, &amp;#92;, &amp;#92;dots, p)&quot; /&gt; de &lt;img alt=&quot;&amp;#92;pi(r) |_{&amp;#92;omega_{ij}}&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%5Cpi%28r%29+%7C_%7B%5Comega_%7Bij%7D%7D&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;&amp;#92;pi(r) |_{&amp;#92;omega_{ij}}&quot; /&gt;.&lt;/li&gt;
&lt;li&gt;&lt;img alt=&quot;&amp;#92;rho_{ij} &amp;#92;leftarrow &amp;#92;max(|r_k|)&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%5Crho_%7Bij%7D+%5Cleftarrow+%5Cmax%28%7Cr_k%7C%29&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;&amp;#92;rho_{ij} &amp;#92;leftarrow &amp;#92;max(|r_k|)&quot; /&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;Representar las curvas de nivel de &lt;img alt=&quot;&amp;#92;rho&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%5Crho&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;&amp;#92;rho&quot; /&gt;. La &lt;img alt=&quot;&amp;#92;rho = 1&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%5Crho+%3D+1&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;&amp;#92;rho = 1&quot; /&gt; ser&amp;#225; la frontera de la regi&amp;#243;n de estabilidad absoluta y las &lt;img alt=&quot;&amp;#92;rho &amp;lt; 1&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%5Crho+%3C+1&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;&amp;#92;rho &amp;lt; 1&quot; /&gt; ser&amp;#225;n el interior de la misma.&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h2&gt;C&amp;#243;digo y representaci&amp;#243;n&lt;/h2&gt;
&lt;p&gt;Vamos a incluir el c&amp;#243;digo en un m&amp;#243;dulo para poder acceder a esta funcionalidad m&amp;#225;s f&amp;#225;cilmente. El c&amp;#243;digo completo, a&amp;#241;adiendo documentaci&amp;#243;n y ejemplos con el &lt;a href=&quot;https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt&quot;&gt;est&amp;#225;ndar de documentaci&amp;#243;n de NumPy/SciPy&lt;/a&gt;, quedar&amp;#237;a as&amp;#237;:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
# -*- coding: utf-8 -*-
#
# Regi&amp;#243;n de estabilidad absoluta
# Juan Luis Cano Rodr&amp;#237;guez

import numpy as np

def region_estabilidad(p, X, Y):
    &amp;quot;&amp;quot;&amp;quot;Regi&amp;#243;n de estabilidad absoluta

    Computa la regi&amp;#243;n de estabilidad absoluta de un m&amp;#233;todo num&amp;#233;rico, dados
    los coeficientes de su polinomio caracter&amp;#237;stico de estabilidad.

    Argumentos
    ----------
    p : function
        Acepta un argumento w y devuelve una lista de coeficientes
    X, Y : numpy.ndarray
        Rejilla en la que evaluar el polinomio de estabilidad generada por
        numpy.meshgrid

    Devuelve
    --------
    Z : numpy.ndarray
        Para cada punto de la malla, m&amp;#225;ximo de los valores absolutos de las
        ra&amp;#237;ces del polinomio de estabilidad

    Ejemplos
    --------
    &amp;gt;&amp;gt;&amp;gt; import numpy as np
    &amp;gt;&amp;gt;&amp;gt; x = np.linspace(-3.0, 1.5)
    &amp;gt;&amp;gt;&amp;gt; y = np.linspace(-3.0, 3.0)
    &amp;gt;&amp;gt;&amp;gt; X, Y = np.meshgrid(x, y)
    &amp;gt;&amp;gt;&amp;gt; Z = region_estabilidad(lambda w: [1,
    ... -1 - w - w ** 2 / 2 - w ** 3 / 6 - w ** 4 / 24], X, Y)  # RK4
    &amp;gt;&amp;gt;&amp;gt; import matplotlib.pyplot as plt
    &amp;gt;&amp;gt;&amp;gt; cs = plt.contour(X, Y, Z, np.linspace(0.05, 1.0, 9))
    &amp;gt;&amp;gt;&amp;gt; plt.clabel(cs, inline=1, fontsize=10)  # Para etiquetar los contornos
    &amp;gt;&amp;gt;&amp;gt; plt.show()

    &amp;quot;&amp;quot;&amp;quot;

    Z = np.zeros_like(X)
    w = X + Y * 1j
&amp;#160; &amp;#160; 
    for j in range(len(X)):
        for i in range(len(Y)):
            r = np.roots(p(w[i, j]))
            Z[i, j] = np.max(abs(r if np.any(r) else 0))

    return Z

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Como sucede casi siempre en Python, el c&amp;#243;digo es casi una traducci&amp;#243;n literal del algoritmo. Vamos a explicar un poco el c&amp;#243;digo:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Obtenemos los coeficientes del polinomio para &lt;code&gt;w[i, j]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Calculamos las ra&amp;#237;ces de dicho polinomio con &lt;a href=&quot;http://docs.scipy.org/doc/numpy/reference/generated/numpy.roots.html&quot;&gt;&lt;code&gt;np.roots&lt;/code&gt;&lt;/a&gt;, que acepta un array de rango 1 o equivalente (por esto no se puede vectorizar el bucle) y devuelve un array con las ra&amp;#237;ces del polinomio.&lt;/li&gt;
&lt;li&gt;La expresi&amp;#243;n &lt;code&gt;r if np.any(r) else 0&lt;/code&gt; es un &lt;a href=&quot;http://docs.python.org/reference/expressions.html#conditional-expressions&quot;&gt;condicional ternario&lt;/a&gt;, y tiene la misi&amp;#243;n de devolver un 0 si el polinomio no tiene ra&amp;#237;ces (porque todos los coeficientes se han hecho nulos, por ejemplo) para que la funci&amp;#243;n &lt;code&gt;np.max&lt;/code&gt; no reciba un array vac&amp;#237;o. Es equivalente a&lt;br /&gt;
&lt;pre class=&quot;brush: python;&quot;&gt;
if np.any(r):
    return r
else:
    return 0
&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;Calculamos el valor absoluto de estas ra&amp;#237;ces.&lt;/li&gt;
&lt;li&gt;Con la funci&amp;#243;n &lt;a href=&quot;http://docs.scipy.org/doc/numpy/reference/generated/numpy.amax.html#numpy.amax&quot;&gt;&lt;code&gt;np.max&lt;/code&gt;&lt;/a&gt; calculamos el mayor de estos valores.&lt;/li&gt;
&lt;li&gt;Lo asignamos a &lt;code&gt;Z[i, j]&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Resultados&lt;/h2&gt;
&lt;p&gt;Una vez tenemos esto en un archivo &lt;code&gt;region_estabilidad.py&lt;/code&gt;, si abrimos un int&amp;#233;rprete de IPython en el mismo directorio ser&amp;#225; tan sencillo como&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [1]: import numpy as np

In [2]: x = np.linspace(-3.0, 1.5)

In [3]: y = np.linspace(-3.0, 3.0)

In [4]: X, Y = np.meshgrid(x, y)

In [5]: def p(w):
   ...:     &amp;quot;&amp;quot;&amp;quot;Polinomio de estabilidad del m&amp;#233;todo RK4.&amp;quot;&amp;quot;&amp;quot;
   ...:     return [1, -1 - w - w ** 2 / 2 - w ** 3 / 6 - w ** 4 / 24]
   ...:

In [6]: from region_estabilidad import region_estabilidad

In [7]: Z = region_estabilidad(p, X, Y)

In [8]: import matplotlib.pyplot as plt

In [9]: plt.contour(X, Y, Z, np.linspace(0.0, 1.0, 9))
Out[9]:

In [10]: plt.show()
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;El segundo argumento de &lt;code&gt;plt.contour&lt;/code&gt; es para especificar los niveles que queremos pintar (normalmente s&amp;#243;lo nos interesar&amp;#225; hasta el 1.0). Podemos obtener resultados similares a estos:&lt;/p&gt;
&lt;div class=&quot;wp-caption aligncenter&quot; id=&quot;attachment_327&quot; style=&quot;width: 360px;&quot;&gt;&lt;a href=&quot;http://pybonacci.files.wordpress.com/2012/04/ab3.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot; wp-image-327&quot; height=&quot;420&quot; src=&quot;http://pybonacci.files.wordpress.com/2012/04/ab3.png?w=350&amp;amp;h=420&quot; title=&quot;Adams-Bashfort 3&quot; width=&quot;350&quot; /&gt;&lt;/a&gt;&lt;p class=&quot;wp-caption-text&quot;&gt;Regi&amp;#243;n de estabilidad absoluta de un m&amp;#233;todo Adams-Bashforth 3&lt;/p&gt;&lt;/div&gt;
&lt;div class=&quot;wp-caption aligncenter&quot; id=&quot;attachment_328&quot; style=&quot;width: 360px;&quot;&gt;&lt;a href=&quot;http://pybonacci.files.wordpress.com/2012/04/rk42.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot; wp-image-328&quot; height=&quot;420&quot; src=&quot;http://pybonacci.files.wordpress.com/2012/04/rk42.png?w=350&amp;amp;h=420&quot; title=&quot;Runge-Kutta 4&quot; width=&quot;350&quot; /&gt;&lt;/a&gt;&lt;p class=&quot;wp-caption-text&quot;&gt;Regi&amp;#243;n de estabilidad absoluta de un m&amp;#233;todo Runge-Kutta 4&lt;/p&gt;&lt;/div&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;Y hasta aqu&amp;#237; llega el art&amp;#237;culo de hoy. Espero que os haya resultado interesante y &amp;#250;til, no olvid&amp;#233;is difundir y comentar &lt;img alt=&quot;:)&quot; class=&quot;wp-smiley&quot; src=&quot;http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif&quot; /&gt; &lt;/p&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;&amp;#161;Un saludo!&lt;/p&gt;
&lt;h2&gt;Referencias&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;HERN&amp;#193;NDEZ, Juan A.&amp;#160;&lt;em&gt;C&amp;#225;lculo Num&amp;#233;rico en Ecuaciones Diferenciales Ordinarias&lt;/em&gt;. ADI, 2001.&lt;/li&gt;
&lt;li&gt;LEVEQUE, Randall J.&amp;#160;&lt;em&gt;Finite Difference Methods for Ordinary and Partial Differential Equations&lt;/em&gt;.&amp;#160;Society for Industrial and Applied Mathematics, 2007.&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;Filed under: &lt;a href=&quot;http://pybonacci.wordpress.com/category/basico/&quot;&gt;B&amp;#225;sico&lt;/a&gt; Tagged: &lt;a href=&quot;http://pybonacci.wordpress.com/tag/ecuaciones-diferenciales/&quot;&gt;ecuaciones diferenciales&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/matplotlib/&quot;&gt;matplotlib&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/metodos-numericos/&quot;&gt;m&amp;#233;todos num&amp;#233;ricos&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/numpy/&quot;&gt;numpy&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/python/&quot;&gt;python&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gocomments/pybonacci.wordpress.com/246/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/comments/pybonacci.wordpress.com/246/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godelicious/pybonacci.wordpress.com/246/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/delicious/pybonacci.wordpress.com/246/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gofacebook/pybonacci.wordpress.com/246/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/facebook/pybonacci.wordpress.com/246/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gotwitter/pybonacci.wordpress.com/246/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/twitter/pybonacci.wordpress.com/246/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gostumble/pybonacci.wordpress.com/246/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/stumble/pybonacci.wordpress.com/246/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godigg/pybonacci.wordpress.com/246/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/digg/pybonacci.wordpress.com/246/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/goreddit/pybonacci.wordpress.com/246/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/reddit/pybonacci.wordpress.com/246/&quot; /&gt;&lt;/a&gt; &lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://stats.wordpress.com/b.gif?host=pybonacci.wordpress.com&amp;#038;blog=33759577&amp;#038;post=246&amp;#038;subd=pybonacci&amp;#038;ref=&amp;#038;feed=1&quot; width=&quot;1&quot; /&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://joedicastro.com/sincronizar-bitbucket-y-github.html
            </guid>
            <title>
                joe di castro: Sincronizar Bitbucket y GitHub
            </title>
            <pubDate>
                Thu, 26 Apr 2012 19:15:00 GMT
            </pubDate>
            <link>
                http://joedicastro.com/sincronizar-bitbucket-y-github.html
            </link>
            <description>
                &lt;p&gt;Para mis proyectos empleo generalmente &lt;a href=&quot;http://mercurial.selenic.com/&quot;&gt;mercurial&lt;/a&gt; (hg) como sistema de
control de versiones, porque est&amp;#225; hecho en Python y me parece m&amp;#225;s elegante y
agradable de usar que &lt;a href=&quot;http://git-scm.com/&quot;&gt;git&lt;/a&gt;, aunque empleo git para algunas tareas, como
gestionar los plugins de &lt;a href=&quot;http://www.vim.org&quot;&gt;Vim&lt;/a&gt;. Del mismo modo, el emplear hg como 
&lt;a href=&quot;http://es.wikipedia.org/wiki/Programas_para_control_de_versiones&quot;&gt;DCVS&lt;/a&gt; me llevaba de forma natural a emplear &lt;a href=&quot;http://bitbucket.org&quot;&gt;Bitbucket&lt;/a&gt; como
alojamiento para mis repositorios p&amp;#250;blicos. &lt;/p&gt;
&lt;p&gt;Siempre me ha gustado &lt;strong&gt;Bitbucket&lt;/strong&gt;, su estilo sencillo, pero muy potente y creo que
tiene algunas caracter&amp;#237;sticas que son superiores a las de sus rivales (el &lt;a href=&quot;http://blog.bitbucket.org/2011/12/08/pull-requests-with-side-by-side-diffs/&quot;&gt;diff
side-by-side&lt;/a&gt;, por ejemplo&lt;sup id=&quot;fnref:gt&quot;&gt;&lt;a href=&quot;http://joedicastro.com/feeds/tags/python.rss.xml#fn:gt&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;). Pero tambi&amp;#233;n tengo claro que si hay alg&amp;#250;n
alojamiento de c&amp;#243;digo en la red que destaca sobre todos los dem&amp;#225;s es &lt;a href=&quot;http://github.com&quot;&gt;GitHub&lt;/a&gt;,
&quot;todo&quot; el mundo est&amp;#225; all&amp;#237; y de alg&amp;#250;n modo, est&amp;#225;s &quot;obligado&quot; a estar. &lt;strong&gt;GitHub&lt;/strong&gt;
tiene algunas caracter&amp;#237;sticas muy potentes y en ciertos aspectos es muy superior
a Bitbucket, aunque me sigue gustando m&amp;#225;s el &lt;em&gt;feeling&lt;/em&gt; de este &amp;#250;ltimo. &lt;/p&gt;
&lt;h2 id=&quot;hg__git&quot;&gt;Hg != Git&lt;/h2&gt;
&lt;p&gt;Me plante&amp;#233; entonces hace unos d&amp;#237;as que lo mejor era mantener una replica de mis
repositorios alojados en Bitbucket en GitHub, como dice el refr&amp;#225;n, &lt;em&gt;Nunca tengas
todos tus huevos en una misma cesta&lt;/em&gt;. El problema es que aunque Bitbucket soporta 
repositorios tanto en mercurial como en git (para competir con GitHub), GitHub
solo soporta repositorios en Git. Y dado el &amp;#233;xito que tienen, dudo mucho que
tengan intenci&amp;#243;n alguna de soportar otro sistema de versiones distinto a Git. &lt;/p&gt;
&lt;p&gt;T&amp;#233;cnicamente es posible mantener un repositorio con los dos dcvs a la vez, pero
maldita la gracia que me hac&amp;#237;a, ademas de que no es nada aconsejable por el
incremento de tama&amp;#241;o en disco que esto supondr&amp;#237;a. Entonces, &amp;#191;como hacer para poder
alojar un repositorio mantenido con mercurial en un alojamiento que solo soporta
Git? La soluci&amp;#243;n, &lt;strong&gt;hg-git&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;hg-git&quot;&gt;hg-git&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;http://hg-git.github.com/&quot;&gt;hg-git&lt;/a&gt; es un plugin para mercurial que permite sincronizar el repositorio
local en hg con un repositorio en git, admitiendo tanto &lt;em&gt;push&lt;/em&gt; como &lt;em&gt;pull&lt;/em&gt; y sin
perdidas de informaci&amp;#243;n. Gracias a este plugin, podemos alojar el repositorio en
los dos sitios a la vez, empleando solo mercurial para gestionarlo.&lt;/p&gt;
&lt;p&gt;Instalarlo es muy f&amp;#225;cil (desde &lt;code&gt;easy_install&lt;/code&gt; o &lt;code&gt;pip&lt;/code&gt;) y emplearlo tambi&amp;#233;n.
Primero necesitas habilitarlo en el fichero &lt;code&gt;~/.hgrc&lt;/code&gt;, as&amp;#237; como la extensi&amp;#243;n 
bookmarks que necesita para trabajar.&lt;/p&gt;
&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;[extensions]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;hgext.bookmarks&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;hggit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;A continuaci&amp;#243;n tienes que ir a tu repositorio y asignarle un &lt;code&gt;bookmark&lt;/code&gt; a la
rama que tengas por defecto (suele ser &lt;code&gt;default&lt;/code&gt;) o a &lt;code&gt;tip&lt;/code&gt; con el nombre de
&lt;code&gt;master&lt;/code&gt; (el nombre de las ramas por defecto en git), es decir:&lt;/p&gt;
&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; hg bookmark -r default master -f
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Y luego emplearlo es tan sencillo como si fuera un repositorio de mercurial, por
ejemplo un push:&lt;/p&gt;
&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; hg push git+ssh://git@github.com/joedicastro/joedicastro.com.git
&lt;/pre&gt;&lt;/div&gt;


&lt;h2 id=&quot;sincronizar_el_repositorio_con_bitbucket_y_github&quot;&gt;Sincronizar el repositorio con Bitbucket y GitHub&lt;/h2&gt;
&lt;p&gt;Ahora, lo que tampoco me apetec&amp;#237;a era tener que andar haciendo un push cada vez
para cada alojamiento, lo ideal es que cada vez que hiciera un push a un
sitio se sincronizara tambi&amp;#233;n el otro de forma autom&amp;#225;tica. La soluci&amp;#243;n
pasa por emplear los &lt;em&gt;paths&lt;/em&gt; para definir alias para los repositorios remotos y
un &lt;em&gt;hook&lt;/em&gt; para automatizar la sincronizaci&amp;#243;n. &lt;/p&gt;
&lt;p&gt;Definir los alias con &lt;em&gt;paths&lt;/em&gt; es realmente sencillo, nos vamos al fichero
&lt;code&gt;.hg/hgrc&lt;/code&gt; del repositorio local y a&amp;#241;adimos esto (e.g. el repo de este blog):&lt;/p&gt;
&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;[paths]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;github&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;git+ssh://git@github.com:joedicastro/joedicastro.com.git&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;bitbucket&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ssh://hg@bitbucket.org/joedicastro/joedicastro.com&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;De este modo, realizar un &lt;code&gt;push&lt;/code&gt; es tan sencillo como:&lt;/p&gt;
&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; hg push bitbucket
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Ahora necesitamos crear el &lt;code&gt;hook&lt;/code&gt; que nos sincronice los dos alojamientos. Hay
en la red varias soluciones para esto, por ejemplo &lt;a href=&quot;http://morgangoose.com/blog/2010/09/29/github-and-bitbucket-hooks/&quot;&gt;esta&lt;/a&gt; y &lt;a href=&quot;http://wiki.ddenis.com/index.php?title=Sync_BitBucket_and_GitHub&quot;&gt;esta&lt;/a&gt;, 
pero ninguna de las dos acababa de convencerme, la una por emplear un script
bash que entraba muy f&amp;#225;cilmente en un bucle infinito y la otra por necesitar
otro modulo externo, que en mi caso no acababa de funcionar. As&amp;#237;
que bas&amp;#225;ndome en la idea del script bash del primero, decid&amp;#237; crearme uno en
Python que funcionara correctamente y me solucionara el problema. &lt;/p&gt;
&lt;p&gt;El c&amp;#243;digo del &lt;code&gt;hook&lt;/code&gt; es el siguiente:&lt;/p&gt;
&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c&quot;&gt;#!/usr/bin/env python&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# encoding: utf-8&lt;/span&gt;

&lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    bb_gh_sync.py: Mercurial hook to keep synced a repo to Bitbucket &amp;amp; GitHub.&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;#==============================================================================&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# This script maintain synced a repository to booth github and bitbucket sites,&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# using only a local mercurial repository. To do this, makes use of hg-git, the&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# paths defined in my local hg repo and the environment variable given by hg, to&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# push to the site non described in the command line argument. This way, it's&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# irrelevant which site I decided to push every time, booth are done by this&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# hook.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;##==============================================================================&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;#==============================================================================&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    Copyright 2012 joe di castro &amp;lt;joe@joedicastro.com&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    This program is free software: you can redistribute it and/or modify&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    it under the terms of the GNU General Public License as published by&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    the Free Software Foundation, either version 3 of the License, or&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    (at your option) any later version.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    This program is distributed in the hope that it will be useful,&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    GNU General Public License for more details.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    You should have received a copy of the GNU General Public License&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#    along with this program.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#==============================================================================&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;__author__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;joe di castro &amp;lt;joe@joedicastro.com&amp;gt;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;__license__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;GNU General Public License version 3&amp;quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;__date__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;23/04/2012&amp;quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;__version__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;0.1&amp;quot;&lt;/span&gt;

&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;tempfile&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gettempdir&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;subprocess&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;call&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Main section&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;tmp_dir&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gettempdir&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;lock_file&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tmp_dir&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;bb_gh.lock&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;c&quot;&gt;# make sure that only runs once for each repository&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exists&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lock_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lock_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;w&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;c&quot;&gt;# if pushed to bitbucket, push to github too&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;environ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'HG_ARGS'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;push bitbucket&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;/usr/bin/env&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;hg&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;push&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;github&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
        &lt;span class=&quot;c&quot;&gt;# et viceversa...&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;environ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'HG_ARGS'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;push github&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;/usr/bin/env&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;hg&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;push&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;bitbucket&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lock_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;__main__&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Ahora solo tenemos que editar nuestro fichero &lt;code&gt;~/.hgrc&lt;/code&gt; para habilitarlo y ya
estar&amp;#237;a listo para funcionar. Editamos el fichero y le a&amp;#241;adimos estas lineas:&lt;/p&gt;
&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;[hooks]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;post-push&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;$HOME/dotfiles/hg/bb_gh_sync.py&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Ahora, si hacemos un push a Bitbucket, el hace autom&amp;#225;ticamente un push tambi&amp;#233;n a
GitHub al acabar el primero, y viceversa. De este modo, hacer un push a ambos
alojamientos es tan sencillo como:&lt;/p&gt;
&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt; hg push bitbucket
&lt;span class=&quot;go&quot;&gt;pushing to ssh://hg@bitbucket.org/joedicastro/joedicastro.com&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;running ssh hg@bitbucket.org 'hg -R joedicastro/joedicastro.com serve --stdio'&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;searching for changes&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;no changes found&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;running hook post-push: $HOME/dotfiles/hg/bb_gh.py&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;pushing to git+ssh://git@github.com:joedicastro/joedicastro.com.git&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;creating and sending data&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[&amp;quot;git-receive-pack 'joedicastro/joedicastro.com.git'&amp;quot;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    github::refs/heads/master =&amp;gt; GIT:198e8cc9&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;running hook post-push: $HOME/dotfiles/hg/bb_gh.py&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;De este modo puedo mantener copias de los repositorios locales en ambos sitios
de manera autom&amp;#225;tica y sincronizada, sin preocuparme, ni hacer un trabajo extra.
Eso si, conviene prescindir de los wikis y documentarlo todo a trav&amp;#233;s de ficheros
&lt;code&gt;README.md&lt;/code&gt; en formato Markdown para facilitar la integraci&amp;#243;n de los dos sitios.
Lo que por otro lado tambi&amp;#233;n ayuda a mantenerlos actualizados de manera m&amp;#225;s sencilla.&lt;/p&gt;
&lt;div class=&quot;footnote&quot;&gt;
&lt;hr /&gt;
&lt;ol&gt;
&lt;li id=&quot;fn:gt&quot;&gt;
&lt;p&gt;Bueno, algunos rivales como &lt;a href=&quot;http://gitorious.org/&quot;&gt;Gitorius&lt;/a&gt;, tambi&amp;#233;n soportan esta caracter&amp;#237;stica
&amp;#160;&lt;a href=&quot;http://joedicastro.com/feeds/tags/python.rss.xml#fnref:gt&quot; rev=&quot;footnote&quot; title=&quot;Jump back to footnote 1 in the text&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://python.majibu.org/preguntas/1455/campos-no-obligatorios-en-django-admin
            </guid>
            <title>
                python majibu: Campos no obligatorios en django admin
            </title>
            <pubDate>
                Tue, 24 Apr 2012 21:26:48 GMT
            </pubDate>
            <link>
                http://python.majibu.org/preguntas/1455/campos-no-obligatorios-en-django-admin
            </link>
            <description>
                &lt;p&gt;Tengo un formulario en django administration, el problema es que es un formulario con muchos campos, quiero que todos los campos se muestren pero no quiero que todos sean obligatorios solo uno o dos.
Esto lo puedo definir bien en los formularios normales de django.forms pero en el django admin usando el admin.ModelAdmin no se como se hace. Tampoco encuentro nada en &lt;a href=&quot;https://docs.djangoproject.com/en/dev/ref/contrib/admin/&quot;&gt;link text&lt;/a&gt;
Tengo de momento definido el admin.py de esta forma. Pero como digo todos los campos me salen como obligatorios.&lt;/p&gt;
&lt;table class=&quot;codehilitetable&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;linenos&quot;&gt;&lt;div class=&quot;linenodiv&quot;&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CurriculoAdmin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;admin&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ModelAdmin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;list_display&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'__unicode__'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;s&quot;&gt;'nombre'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'apellidos'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'profesion'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'poblacion'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;s&quot;&gt;'provincia'&lt;/span&gt;
                &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;list_filter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'profesion'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'provincia'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;save_model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;obj&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;form&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;change&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;obj&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;autor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;obj&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;save&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://pybonacci.wordpress.com/?p=37
            </guid>
            <title>
                Pybonacci: Estad&amp;#237;stica en Python con SciPy (I)
            </title>
            <pubDate>
                Sat, 21 Apr 2012 16:46:31 GMT
            </pubDate>
            <link>
                http://pybonacci.wordpress.com/2012/04/21/estadistica-en-python-con-scipy/
            </link>
            <description>
                &lt;h2&gt;Introducci&amp;#243;n&lt;/h2&gt;
&lt;p&gt;Hoy vamos a ver c&amp;#243;mo trabajar con variable aleatoria con el m&amp;#243;dulo &lt;code&gt;stats&lt;/code&gt; de la biblioteca Scipy. Scipy viene con numerosas &lt;a href=&quot;http://docs.scipy.org/doc/scipy/reference/stats.html&quot;&gt;distribuciones de probabilidad&lt;/a&gt;, tanto discretas como continuas, y adem&amp;#225;s pone a nuestra disposici&amp;#243;n herramientas para crear nuestras propias distribuciones y multitud de herramientas para hacer c&amp;#225;lculos estad&amp;#237;sticos. En esta primera parte nos centraremos en c&amp;#243;mo manejar esas distribuciones y sus funciones de distribuci&amp;#243;n, c&amp;#243;mo representarlas con matplotlib y c&amp;#243;mo definir nuevas distribuciones.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;En esta entrada se ha usado python 2.7.3, numpy 1.6.1, matplotlib 1.1.0&amp;#160;y scipy 0.10.1.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;span id=&quot;more-37&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Nota:&lt;/strong&gt; En mi opini&amp;#243;n la documentaci&amp;#243;n de este m&amp;#243;dulo deja un poco que desear. No resulta demasiado did&amp;#225;ctica, hay algunas imprecisiones y cosas que directamente no tienen sentido o est&amp;#225;n mal. En cuanto sepas manejarlo un poco puedes usar de referencia en primer enlace de la entrada.&lt;/p&gt;
&lt;h2&gt;Distribuciones de variable continua&lt;/h2&gt;
&lt;p&gt;Entre las muchas &lt;a href=&quot;http://docs.scipy.org/doc/scipy/reference/stats.html#continuous-distributions&quot;&gt;distribuciones continuas&lt;/a&gt; que tiene SciPy vamos a ver un ejemplo de c&amp;#243;mo manejar la distribuci&amp;#243;n normal o gaussiana. Primero vamos a importar un par de m&amp;#243;dulos&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [1]: import numpy as np

In [2]: import scipy.stats as st
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Todas las distribuciones continuas est&amp;#225;n definidas en funci&amp;#243;n de dos &lt;strong&gt;par&amp;#225;metros&lt;/strong&gt;: &lt;code&gt;loc&lt;/code&gt; y &lt;code&gt;scale&lt;/code&gt;, que juegan distinto papel en funci&amp;#243;n de la distribuci&amp;#243;n que manejemos. Por ejemplo, para la normal, &lt;code&gt;loc&lt;/code&gt; es la media y por tanto el centro de la distribuci&amp;#243;n y &lt;code&gt;scale&lt;/code&gt; es la desviaci&amp;#243;n t&amp;#237;pica y puede verse como un factor de escala (de ah&amp;#237; los nombres de los par&amp;#225;metros). Por otro lado, para la distribuci&amp;#243;n uniforme, &lt;code&gt;loc&lt;/code&gt; y &lt;code&gt;scale&lt;/code&gt; son los extremos del intervalo en el que toma valores la variable.&lt;/p&gt;
&lt;p&gt;Tenemos dos formas de manejar las distribuciones: una de ellas es crear un objeto que represente a &lt;strong&gt;la distribuci&amp;#243;n con los par&amp;#225;metros fijados&lt;/strong&gt;, y acceder despu&amp;#233;s a todos sus m&amp;#233;todos (&amp;#171;frozen distribution&amp;#187;), de esta manera:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [3]: rv1 = st.norm()  # Normal est&amp;#225;ndar

In [4]: rv1.cdf(0.5)  # Evaluamos la funci&amp;#243;n de distribuci&amp;#243;n en 0.5
Out[4]: 0.69146246127401312

In [5]: x = np.linspace(0.0, 1.0)

In [6]: rv1.pdf(x)  # Densidad de probabilidad en el intervalo [0.0, 1.0]
Out[6]:
array([ 0.39894228,  0.39885921,  0.39861011,  0.39819528,  0.39761524,
        0.39687072,  0.39596264,  0.39489214,  0.39366054,  0.39226937,
        0.39072035,  0.38901539,  0.38715659,  0.38514623,  0.38298676,
        0.38068082,  0.37823119,  0.37564085,  0.37291289,  0.37005059,
        0.36705736,  0.36393672,  0.36069236,  0.35732807,  0.35384775,
        0.35025541,  0.34655518,  0.34275126,  0.33884794,  0.33484957,
        0.3307606 ,  0.3265855 ,  0.32232884,  0.31799518,  0.31358916,
        0.30911541,  0.30457861,  0.29998342,  0.29533453,  0.29063661,
        0.28589432,  0.28111231,  0.27629519,  0.27144753,  0.26657387,
        0.26167871,  0.25676648,  0.25184154,  0.24690821,  0.24197072])

In [7]: rv2 = st.norm(2.0, 0.0)  # Normal (2.0, 0.0)

In [8]: rv3 = st.norm(loc=-1.0, scale=np.sqrt(0.5))  # Media -1.0 y varianza 0.5

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;La otra manera ser&amp;#237;a llamar en cada momento a la funci&amp;#243;n que queramos evaluar, pasando los par&amp;#225;metros correspondientes, de manera que no se crea una distribuci&amp;#243;n concreta:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [9]: st.norm.cdf(0.5)  # Funci&amp;#243;n de distribuci&amp;#243;n de una normal est&amp;#225;ndar en 0.5
Out[9]: 0.69146246127401312

In [10]: st.norm.pdf(x, -1.0, np.sqrt(0.5))  # Densidad de una normal (-1.0, 0.5) en [0.0, 1.0]
Out[10]:
array([ 0.20755375,  0.19916976,  0.1909653 ,  0.18294635,  0.17511819,
        0.16748543,  0.16005198,  0.15282109,  0.14579538,  0.13897686,
        0.13236692,  0.12596638,  0.11977553,  0.11379411,  0.10802137,
        0.10245611,  0.09709665,  0.09194093,  0.08698648,  0.08223049,
        0.0776698 ,  0.07330098,  0.0691203 ,  0.06512379,  0.06130727,
        0.05766636,  0.05419651,  0.05089303,  0.04775112,  0.04476588,
        0.04193231,  0.0392454 ,  0.03670008,  0.03429126,  0.03201387,
        0.02986284,  0.02783314,  0.0259198 ,  0.02411789,  0.02242256,
        0.02082904,  0.01933266,  0.01792884,  0.01661312,  0.01538113,
        0.01422864,  0.01315155,  0.01214588,  0.01120776,  0.01033349])
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Esto ser&amp;#225; &amp;#250;til cuando queramos hacer ajustes o estimaciones sobre los par&amp;#225;metros de la distribuci&amp;#243;n, como veremos en la pr&amp;#243;xima entrega.&lt;/p&gt;
&lt;p&gt;Para quien no conozca los nombres en ingl&amp;#233;s, los m&amp;#233;todos m&amp;#225;s importantes son&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Salida pseudoaleatoria (&amp;#171;random variates&amp;#187; &lt;code&gt;rvs&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Funci&amp;#243;n densidad de probabilidad (&amp;#171;probability density function&amp;#187; &lt;code&gt;pdf&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Funci&amp;#243;n de distribuci&amp;#243;n (&amp;#171;cumulative distribution function&amp;#187; &lt;code&gt;cdf&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;y todos ellos, y alguno m&amp;#225;s, est&amp;#225;n &lt;strong&gt;vectorizados&lt;/strong&gt;, lo que significa que les podemos pasar un array de NumPy y obtendremos un array de valores.&lt;/p&gt;
&lt;h3&gt;Representaci&amp;#243;n gr&amp;#225;fica&lt;/h3&gt;
&lt;p&gt;Como los m&amp;#233;todos b&amp;#225;sicos est&amp;#225;n vectorizados, es muy sencillo representarlos gr&amp;#225;ficamente en la manera a la que estamos acostumbrados, utilizando arrays de NumPy. Simplemente tenemos que escribir&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [11]: import matplotlib.pyplot as plt

In [12]: x = np.linspace(0.0, 1.0)

In [13]: plt.plot(x, st.norm.pdf(x, -1.0, np.sqrt(0.5)))
Out[13]: []

In [14]: plt.show()

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Y podemos obtener bonitas figuras como esta.&lt;/p&gt;
&lt;div class=&quot;wp-caption aligncenter&quot; id=&quot;attachment_217&quot; style=&quot;width: 458px;&quot;&gt;&lt;a href=&quot;http://pybonacci.files.wordpress.com/2012/04/normal_pdf1.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot; wp-image-217&quot; height=&quot;336&quot; src=&quot;http://pybonacci.files.wordpress.com/2012/04/normal_pdf1.png?w=448&amp;amp;h=336&quot; title=&quot;Distribuciones normales&quot; width=&quot;448&quot; /&gt;&lt;/a&gt;&lt;p class=&quot;wp-caption-text&quot;&gt;Funci&amp;#243;n de densidad de probabilidad de varias distribuciones normales (inspiraci&amp;#243;n: http://commons.wikimedia.org/wiki/File:Normal_Distribution_PDF.svg)&lt;/p&gt;&lt;/div&gt;
&lt;h3&gt;Definir distribuciones&lt;/h3&gt;
&lt;p&gt;La manera de crear nuestras propias distribuciones continuas con SciPy es extender la clase &lt;a href=&quot;http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rv_continuous.html&quot;&gt;&lt;code&gt;rv_continuous&lt;/code&gt;&lt;/a&gt; y definir o bien su funci&amp;#243;n de densidad o su funci&amp;#243;n de distribuci&amp;#243;n. Las clases y la herencia son conceptos de la &lt;a href=&quot;http://es.wikipedia.org/wiki/Programaci%C3%B3n_orientada_a_objetos&quot;&gt;Programaci&amp;#243;n Orientada a Objetos&lt;/a&gt;, pero no es nuestra intenci&amp;#243;n meternos a fondo en estos temas. De igual manera que hemos hecho &lt;code&gt;rv = st.norm()&lt;/code&gt; para crear un objeto distribuci&amp;#243;n al que manipular, queremos un mecanismo parecido para hacer &lt;code&gt;rv = nueva_dist()&lt;/code&gt;, y para eso hemos de definir &lt;code&gt;nueva_dist&lt;/code&gt; primero.&lt;/p&gt;
&lt;p&gt;Por ejemplo, supongamos que queremos definir una distribuci&amp;#243;n uniforme cuya funci&amp;#243;n de densidad es&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;f(x) = -&amp;#92;ln{x} &amp;#92;quad x &amp;#92;in (0, 1],&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=f%28x%29+%3D+-%5Cln%7Bx%7D+%5Cquad+x+%5Cin+%280%2C+1%5D%2C&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;f(x) = -&amp;#92;ln{x} &amp;#92;quad x &amp;#92;in (0, 1],&quot; /&gt;&lt;/p&gt;
&lt;p&gt;el c&amp;#243;digo ser&amp;#237;a el siguiente&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [15]: from scipy.stats import rv_continuous

In [16]: class variable_gen(rv_continuous):
   ....:     &amp;quot;&amp;quot;&amp;quot;Variable aleatoria continua de distribuci&amp;#243;n logar&amp;#237;tmica.&amp;quot;&amp;quot;&amp;quot;
   ....:     def _pdf(self, x):
   ....:         return -log(x)
   ....:

In [17]: variable_gen?
Type:       type
Base Class: &amp;lt;type 'type'&amp;gt;
String Form:&amp;lt;class '__main__.variable_gen'&amp;gt;
Namespace:  Interactive
Definition: variable_gen(self, *args, **kwds)
Docstring:  Variable aleatoria continua de distribuci&amp;#243;n logar&amp;#237;tmica.
Constructor information:
 Definition:variable_gen(self, momtype=1, a=None, b=None, xa=-10.0, xb=10.0, xtol=1e-14, badvalue=None, name=None, longname=None, shapes=None, extradoc=None)

In [18]: variable = variable_gen(a=0.0, b=1.0, name=&amp;quot;variable&amp;quot;)

In [19]: variable.pdf(0.0)
/usr/bin/ipython2:4: RuntimeWarning: divide by zero encountered in log

Out[19]: inf

In [20]: from scipy.integrate import quad

In [21]: from numpy import inf

In [22]: quad(variable.pdf, -inf, inf)
Out[22]: (0.9999999999999962, 6.149525333398742e-12)

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Lo que hemos hecho ha sido&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Definir la clase &lt;code&gt;variable_gen&lt;/code&gt;, que hereda las propiedades de &lt;code&gt;rv_continuous&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Escribir la cadena de documentaci&amp;#243;n de la clase.&lt;/li&gt;
&lt;li&gt;Definir su funci&amp;#243;n de densidad de probabilidad.&lt;/li&gt;
&lt;li&gt;Crear una nueva variable, &lt;code&gt;variable&lt;/code&gt;, en la que guardamos un objeto distribuci&amp;#243;n cuya variable recorre el intervalo &lt;img alt=&quot;[0.0, 1.0]&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%5B0.0%2C+1.0%5D&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;[0.0, 1.0]&quot; /&gt; (n&amp;#243;tese que es cerrado).&lt;/li&gt;
&lt;li&gt;Comprobar qu&amp;#233; pasa en 0. Nada que no supi&amp;#233;ramos.&lt;/li&gt;
&lt;li&gt;Comprobar que la funci&amp;#243;n densidad est&amp;#225; normalizada integr&amp;#225;ndola sobre la recta real (el primer n&amp;#250;mero es el valor de la integral y el segundo una estimaci&amp;#243;n del error, como podemos ver en la documentaci&amp;#243;n de la funci&amp;#243;n &lt;code&gt;&lt;a href=&quot;http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.quad.html&quot;&gt;quad&lt;/a&gt;)&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;A partir de ahora podemos hacer lo mismo que hemos hecho antes: o bien crear una distribuci&amp;#243;n fija o acceder a los m&amp;#233;todos de la misma directamente. Aunque s&amp;#243;lo hemos dado la funci&amp;#243;n de densidad, comprobamos que tambi&amp;#233;n podemos llamar al resto:&lt;/div&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [23]: rv = variable()  # N&amp;#243;tense los par&amp;#233;ntesis

In [24]: rv.cdf(0.5)
Out[24]: 0.84657359027997248

In [25]: x = np.linspace(0.0, 1.0)

In [25]: rv.cdf(x)
Out[25]:
array([ 0.        ,  0.09983307,  0.17137441,  0.23223723,  0.28616538,
        0.33493698,  0.37959929,  0.42084431,  0.45916388,  0.49492574,
        0.52841535,  0.55986072,  0.58944824,  0.61733311,  0.64364656,
        0.66850105,  0.69199398,  0.71421058,  0.73522599,  0.75510704,
        0.77391348,  0.79169908,  0.8085125 ,  0.82439796,  0.83939582,
        0.8535431 ,  0.86687383,  0.87941944,  0.89120902,  0.90226958,
        0.91262628,  0.92230257,  0.93132042,  0.93970041,  0.94746188,
        0.95462303,  0.961201  ,  0.96721201,  0.97267137,  0.97759362,
        0.98199253,  0.98588117,  0.98927201,  0.99217689,  0.99460713,
        0.9965735 ,  0.99808632,  0.99915544,  0.99979032,  1.        ])

In [26]: rv.rvs()
Out[26]: 0.11391190950607678

In [27]: rv.rvs()
Out[27]: 0.41700479602973284

In [28]: rv.rvs()
Out[28]: 0.00019824204606004107

&lt;/pre&gt;&lt;/p&gt;
&lt;h2&gt;Distribuciones de variable discreta&lt;/h2&gt;
&lt;p&gt;Scipy tambi&amp;#233;n trae unas cuantas &lt;a href=&quot;http://docs.scipy.org/doc/scipy/reference/stats.html#discrete-distributions&quot;&gt;distribuciones discretas&lt;/a&gt; para que no las tengamos que definir nosotros, y se usan de manera similar a las continuas. Por ejemplo, la distribuci&amp;#243;n binomial:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [29]: rv = st.binom(5, 0.5)  # Experimento de Bernoulli 5 veces con probabilidad 0.5

In [30]: k = np.arange(6)

In [31]: pk = rv.pmf(k)

In [32]: pk
Out[32]: array([ 0.03125,  0.15625,  0.3125 ,  0.3125 ,  0.15625,  0.03125])
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Para el caso de distribuciones discretas, la funci&amp;#243;n de densidad se distribuye por la funci&amp;#243;n de probabilidad (&amp;#171;probability mass function&amp;#187; &lt;code&gt;pmf&lt;/code&gt;).&lt;/p&gt;
&lt;h3&gt;Representaci&amp;#243;n gr&amp;#225;fica&lt;/h3&gt;
&lt;p&gt;Ahora representar gr&amp;#225;ficamente una distribuci&amp;#243;n discreta tiene un poco m&amp;#225;s de enjundia que en el caso de distribuciones continuas. Para la funci&amp;#243;n de probabilidad hay al menos dos opciones, en funci&amp;#243;n de los gustos de cada cual: hacer un diagrama de barras con &lt;a href=&quot;http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.bar&quot;&gt;&lt;code&gt;bar&lt;/code&gt;&lt;/a&gt; o uno de l&amp;#237;neas verticales con &lt;a href=&quot;http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.vlines&quot;&gt;&lt;code&gt;vlines&lt;/code&gt;&lt;/a&gt;, como vemos en este fragmento de c&amp;#243;digo:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [33]: plt.vlines(k, 0, pk)  # El segundo argumento da el extremo inferior de las l&amp;#237;neas
Out[33]:

In [34]: plt.plot(k, pk, 'o')  # A&amp;#241;adimos puntos en los extremos
Out[34]: []

In [35]: plt.show()

In [36]: plt.bar(k - 0.5, _81, width=1.0)  # Se resta 0.5 para que las barras est&amp;#233;n centradas
Out[36]:

In [37]: plt.show()

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Se obtienen resultados similares a estos:&lt;/p&gt;
&lt;div class=&quot;wp-caption aligncenter&quot; id=&quot;attachment_232&quot; style=&quot;width: 310px;&quot;&gt;&lt;a href=&quot;http://pybonacci.files.wordpress.com/2012/04/binomial5_05_pmf.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;size-medium wp-image-232&quot; height=&quot;225&quot; src=&quot;http://pybonacci.files.wordpress.com/2012/04/binomial5_05_pmf.png?w=300&amp;amp;h=225&quot; title=&quot;Binomial (5, 1/2)&quot; width=&quot;300&quot; /&gt;&lt;/a&gt;&lt;p class=&quot;wp-caption-text&quot;&gt;Funci&amp;#243;n de probabilidad de una distribuci&amp;#243;n binomial (5, 1/2) con l&amp;#237;neas verticales&lt;/p&gt;&lt;/div&gt;
&lt;div class=&quot;wp-caption aligncenter&quot; id=&quot;attachment_233&quot; style=&quot;width: 310px;&quot;&gt;&lt;a href=&quot;http://pybonacci.files.wordpress.com/2012/04/binomial5_05_pmf2.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;size-medium wp-image-233&quot; height=&quot;225&quot; src=&quot;http://pybonacci.files.wordpress.com/2012/04/binomial5_05_pmf2.png?w=300&amp;amp;h=225&quot; title=&quot;Distribuci&amp;#243;n binomial (5, 1/2)&quot; width=&quot;300&quot; /&gt;&lt;/a&gt;&lt;p class=&quot;wp-caption-text&quot;&gt;Funci&amp;#243;n de probabilidad de una distribuci&amp;#243;n binomial (5, 1/2) con barras&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Para la funci&amp;#243;n de distribuci&amp;#243;n, sabemos que en el caso discreto esta tiene discontinuidades de salto. Para no obtener una gr&amp;#225;fica horrible con puntos unidos que no deber&amp;#237;an estarlo, o bien hacemos otro diagrama de barras o utilizamos &lt;strong&gt;arrays enmascarados&lt;/strong&gt; (&amp;#171;masked arrays&amp;#187; suena menos chistoso). Los &lt;a href=&quot;http://docs.scipy.org/doc/numpy/reference/maskedarray.generic.html#what-is-a-masked-array&quot;&gt;masked arrays&lt;/a&gt; con arrays de NumPy en los que, bien manualmente o bien siguiendo alguna regla o patr&amp;#243;n, hemos marcado algunas entradas como inv&amp;#225;lidas. Son de utilidad cuando, por ejemplo, estamos recogiendo datos y queremos descartar los que sean err&amp;#243;neos o se alejen demasiado de la media.&lt;/p&gt;
&lt;p&gt;Si representamos gr&amp;#225;ficamente arrays enmascarados, matplotlib &lt;em&gt;no&lt;/em&gt; unir&amp;#225; los puntos correspondientes a entradas inv&amp;#225;lidas, que es exactamente lo que queremos (como podemos leer &lt;a href=&quot;http://stackoverflow.com/a/2543391/554319&quot;&gt;en esta respuesta de StackOverflow&lt;/a&gt;). Los elementos que queremos marcar como inv&amp;#225;lidos son aquellos en los que la funci&amp;#243;n da un salto, por lo que comprobaremos la diferencia entre un elemento y el siguiente del array. Para ello usaremos la funci&amp;#243;n &lt;code&gt;roll&lt;/code&gt; de NumPy:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [38]: rv = st.binom(5, 0.5)

In [39]: x = np.linspace(-0.5, 5.5)

In [40]: cdf = rv.cdf(x)

In [41]: deltas = cdf - np.roll(cdf, 1)  # Array de diferencias

In [42]: deltas
Out[42]:
array([-1.     ,  0.     ,  0.     ,  0.     ,  0.     ,  0.03125,
        0.     ,  0.     ,  0.     ,  0.     ,  0.     ,  0.     ,
        0.     ,  0.15625,  0.     ,  0.     ,  0.     ,  0.     ,
        0.     ,  0.     ,  0.     ,  0.3125 ,  0.     ,  0.     ,
        0.     ,  0.     ,  0.     ,  0.     ,  0.     ,  0.3125 ,
        0.     ,  0.     ,  0.     ,  0.     ,  0.     ,  0.     ,
        0.     ,  0.15625,  0.     ,  0.     ,  0.     ,  0.     ,
        0.     ,  0.     ,  0.     ,  0.03125,  0.     ,  0.     ,
        0.     ,  0.     ])

In [43]: cdf = np.ma.masked_where(abs(deltas) &amp;gt; tol, cdf)

In [44]: cdf
Out[44]:
masked_array(data = [-- 0.0 0.0 0.0 0.0 -- 0.03125 0.03125 0.03125 0.03125 0.03125 0.03125
 0.03125 -- 0.1875 0.1875 0.1875 0.1875 0.1875 0.1875 0.1875 -- 0.5 0.5 0.5
 0.5 0.5 0.5 0.5 -- 0.8125 0.8125 0.8125 0.8125 0.8125 0.8125 0.8125 --
 0.96875 0.96875 0.96875 0.96875 0.96875 0.96875 0.96875 -- 1.0 1.0 1.0 1.0],
             mask = [ True False False False False  True False False False False False False
 False  True False False False False False False False  True False False
 False False False False False  True False False False False False False
 False  True False False False False False False False  True False False
 False False],
       fill_value = 1e+20)

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Y se obtiene un diagrama similar a este:&lt;/p&gt;
&lt;div class=&quot;wp-caption aligncenter&quot; id=&quot;attachment_237&quot; style=&quot;width: 310px;&quot;&gt;&lt;a href=&quot;http://pybonacci.files.wordpress.com/2012/04/binomial5_05_cdf.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;size-medium wp-image-237&quot; height=&quot;225&quot; src=&quot;http://pybonacci.files.wordpress.com/2012/04/binomial5_05_cdf.png?w=300&amp;amp;h=225&quot; title=&quot;Distribuci&amp;#243;n binomial (5, 1/2)&quot; width=&quot;300&quot; /&gt;&lt;/a&gt;&lt;p class=&quot;wp-caption-text&quot;&gt;Funci&amp;#243;n de distribuci&amp;#243;n de una distribuci&amp;#243;n binomial (5, 1/2)&lt;/p&gt;&lt;/div&gt;
&lt;h3&gt;Definir distribuciones&lt;/h3&gt;
&lt;p&gt;Definir nuevas distribuciones discretas es a&amp;#250;n m&amp;#225;s sencillo que en el caso continuo. Igual que antes, podemos crear una clase que extienda de, en este caso, &lt;a href=&quot;http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rv_discrete.html&quot;&gt;&lt;code&gt;rv_discrete&lt;/code&gt;&lt;/a&gt;, pero ahora dem&amp;#225;s podemos construir la distribuci&amp;#243;n directamente pasando los &lt;img alt=&quot;(x_k, p_k)&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%28x_k%2C+p_k%29&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;(x_k, p_k)&quot; /&gt; al constructor. Por ejemplo, si queremos construir una distribuci&amp;#243;n discreta con los siguientes datos:&lt;/p&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;th&gt;&lt;img alt=&quot;x_k&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=x_k&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;x_k&quot; /&gt;&lt;/th&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;&lt;img alt=&quot;p_k&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=p_k&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;p_k&quot; /&gt;&lt;/th&gt;
&lt;td&gt;0.1&lt;/td&gt;
&lt;td&gt;0.4&lt;/td&gt;
&lt;td&gt;0.2&lt;/td&gt;
&lt;td&gt;0.3&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;el c&amp;#243;digo ser&amp;#225; el siguiente:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [45]: xk = [1, 2, 3, 4]

In [46]: pk = [0.1, 0.4, 0.2, 0.3]

In [47]: rv = st.rv_discrete(xk[0], xk[-1], values=(xk, pk))

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;y ya podemos acceder a todos los m&amp;#233;todos que hemos visto anteriormente con normalidad.&lt;/p&gt;
&lt;p&gt;Aqu&amp;#237; se termina la primera parte de esta introducci&amp;#243;n al c&amp;#225;lculo estad&amp;#237;stico con SciPy. Espero que te haya resultado &amp;#250;til; no olvides difundirlo en las redes sociales y comentar lo que te apetezca.&lt;/p&gt;
&lt;p&gt;&amp;#161;Un saludo!&lt;/p&gt;
&lt;br /&gt;Filed under: &lt;a href=&quot;http://pybonacci.wordpress.com/category/tutoriales/&quot;&gt;Tutoriales&lt;/a&gt; Tagged: &lt;a href=&quot;http://pybonacci.wordpress.com/tag/estadistica/&quot;&gt;estad&amp;#237;stica&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/matplotlib/&quot;&gt;matplotlib&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/numpy/&quot;&gt;numpy&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/python/&quot;&gt;python&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/scipy/&quot;&gt;scipy&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gocomments/pybonacci.wordpress.com/37/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/comments/pybonacci.wordpress.com/37/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godelicious/pybonacci.wordpress.com/37/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/delicious/pybonacci.wordpress.com/37/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gofacebook/pybonacci.wordpress.com/37/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/facebook/pybonacci.wordpress.com/37/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gotwitter/pybonacci.wordpress.com/37/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/twitter/pybonacci.wordpress.com/37/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gostumble/pybonacci.wordpress.com/37/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/stumble/pybonacci.wordpress.com/37/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godigg/pybonacci.wordpress.com/37/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/digg/pybonacci.wordpress.com/37/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/goreddit/pybonacci.wordpress.com/37/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/reddit/pybonacci.wordpress.com/37/&quot; /&gt;&lt;/a&gt; &lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://stats.wordpress.com/b.gif?host=pybonacci.wordpress.com&amp;#038;blog=33759577&amp;#038;post=37&amp;#038;subd=pybonacci&amp;#038;ref=&amp;#038;feed=1&quot; width=&quot;1&quot; /&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://javaguirre.net/?p=863
            </guid>
            <title>
                JavAguirre.net: M2Crypto from pip in old GNU/Linux OS
            </title>
            <pubDate>
                Thu, 19 Apr 2012 19:47:13 GMT
            </pubDate>
            <link>
                http://javaguirre.net/2012/04/19/m2crypto-from-pip-in-old-gnulinux-os/
            </link>
            <description>
                &lt;p&gt;We had a problem today with &lt;strong&gt;M2Crypto&lt;/strong&gt; package from pip repository in a CentOS server.&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;bash&quot; style=&quot;font-family: monospace;&quot;&gt;... Error: Unable to &lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;find&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'opensslconf-x86_64.h'&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The actual version in pip repositories is 0.21.1, but the setup.py file doesn&amp;#8217;t search for the correct headers in this version of CentOS 5.5 (It&amp;#8217;s old, I know :-) ).&lt;/p&gt;
&lt;p&gt;There&amp;#8217;s an easy workaround to get it working, I &lt;a href=&quot;http://community.zenoss.org/thread/4379&quot;&gt;found it in a Zenoss community thread&lt;/a&gt;, you can just add a new path to search for files to &lt;em&gt;self.swig_opts&lt;/em&gt; list.&lt;/p&gt;
&lt;p&gt;First, we can download it from pip, and modify the &lt;strong&gt;setup.py&lt;/strong&gt; file.&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;python&quot; style=&quot;font-family: monospace;&quot;&gt;pip install -d . &lt;span style=&quot;color: black;&quot;&gt;M2Crypto&lt;/span&gt;==0.21.1
untar M2Crypto-0.21.1.&lt;span style=&quot;color: black;&quot;&gt;tar&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;gz&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;BEFORE&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;python&quot; style=&quot;font-family: monospace;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;#LINE 58&lt;/span&gt;
&lt;span style=&quot;color: #008000;&quot;&gt;self&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;swig_opts&lt;/span&gt; = &lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;'-I%s'&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;%&lt;/span&gt; i &lt;span style=&quot;color: #ff7700; font-weight: bold;&quot;&gt;for&lt;/span&gt; i &lt;span style=&quot;color: #ff7700; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;self&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;include_dirs&lt;/span&gt; + \                                                                                  
                 &lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;opensslIncludeDir&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #008000;&quot;&gt;self&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;swig_opts&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;'-includeall'&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;AFTER&lt;/p&gt;

&lt;div class=&quot;wp_syntax&quot;&gt;&lt;div class=&quot;code&quot;&gt;&lt;pre class=&quot;python&quot; style=&quot;font-family: monospace;&quot;&gt;&lt;span style=&quot;color: #008000;&quot;&gt;self&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;swig_opts&lt;/span&gt; = &lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;'-I%s'&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;%&lt;/span&gt; i &lt;span style=&quot;color: #ff7700; font-weight: bold;&quot;&gt;for&lt;/span&gt; i &lt;span style=&quot;color: #ff7700; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;self&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;include_dirs&lt;/span&gt; + \                                                                                  
                 &lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;opensslIncludeDir&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span style=&quot;color: #008000;&quot;&gt;self&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;swig_opts&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;'-includeall'&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #008000;&quot;&gt;self&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;swig_opts&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;'-I/usr/include/openssl'&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then running &lt;strong&gt;python setup.py install&lt;/strong&gt; might do the trick.&lt;/p&gt;
&lt;h2 class=&quot;related_post_title&quot;&gt;Related Posts&lt;/h2&gt;&lt;ul class=&quot;related_post&quot;&gt;&lt;li&gt;December 31, 2011 -- &lt;a href=&quot;http://javaguirre.net/2011/12/31/generar-claves-ssh-desde-python-sin-meter-contrasena/&quot; title=&quot;Generar claves ssh desde python sin meter contrase&amp;#241;a&quot;&gt;Generar claves ssh desde python sin meter contrase&amp;#241;a&lt;/a&gt; (0)&lt;/li&gt;&lt;li&gt;October 25, 2011 -- &lt;a href=&quot;http://javaguirre.net/2011/10/25/python-virtualenv/&quot; title=&quot;Python virtualenv&quot;&gt;Python virtualenv&lt;/a&gt; (0)&lt;/li&gt;&lt;li&gt;May 14, 2012 -- &lt;a href=&quot;http://javaguirre.net/2012/05/14/raequel-scraping-en-la-web-de-la-rae-con-app-engine/&quot; title=&quot;Raequel, scraping en la web de la rae con app engine&quot;&gt;Raequel, scraping en la web de la rae con app engine&lt;/a&gt; (0)&lt;/li&gt;&lt;/ul&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://python.majibu.org/preguntas/1441/agregar-fields-adicionales-a-autocompletar
            </guid>
            <title>
                python majibu: Agregar fields adicionales a autocompletar
            </title>
            <pubDate>
                Thu, 19 Apr 2012 15:24:50 GMT
            </pubDate>
            <link>
                http://python.majibu.org/preguntas/1441/agregar-fields-adicionales-a-autocompletar
            </link>
            <description>
                &lt;p&gt;Hola tengo un formulario con un campo de b&amp;#250;squeda con autocompletado, me devuelve la identificaci&amp;#243;n de un vendedor, pero necesito que me devuelva la identificaci&amp;#243;n del vendedor, el nombre y apellido.&lt;/p&gt;
&lt;p&gt;Mis modelos:&lt;/p&gt;
&lt;table class=&quot;codehilitetable&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;linenos&quot;&gt;&lt;div class=&quot;linenodiv&quot;&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Usuario&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OneToOneField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rut&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CharField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unique&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;nombre&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CharField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;apellido_paterno&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CharField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;apellido_materno&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CharField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;__unicode__&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;nombre&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;apellido_paterno&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;apellido_materno&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Vendedor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Usuario&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;local&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ForeignKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Local&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Meta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;ordering&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'rut'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'apellido_paterno'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'apellido_materno'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Mi Vista:&lt;/p&gt;
&lt;table class=&quot;codehilitetable&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;linenos&quot;&gt;&lt;div class=&quot;linenodiv&quot;&gt;&lt;pre&gt;1
2
3
4
5&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nd&quot;&gt;@login_required&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;buscar_vendedor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;term&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GET&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'term'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;resultado&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Vendedor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;objects&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rut__icontains&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;term&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user__is_active&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;values_list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'rut'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;flat&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HttpResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;simplejson&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dumps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;resultado&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mimetype&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'application/json'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;La vista anterior me funciona bien pero no se como agregar las fields adicionales que necesito.&lt;/p&gt;
&lt;p&gt;Intente usando otro metodo:&lt;/p&gt;
&lt;table class=&quot;codehilitetable&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;linenos&quot;&gt;&lt;div class=&quot;linenodiv&quot;&gt;&lt;pre&gt;1
2
3
4
5&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nd&quot;&gt;@login_required&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;buscar_vendedor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;term&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GET&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'term'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;resultado&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serializers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serialize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'json'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Vendedor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;objects&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fields&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'rut'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'nombre'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HttpResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;resultado&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mimetype&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'application/json'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Pero no me devuelve el contenido de las fields, pero me devuelve esto:&lt;/p&gt;
&lt;table class=&quot;codehilitetable&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;linenos&quot;&gt;&lt;div class=&quot;linenodiv&quot;&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;[
    {
        &quot;pk&quot;: 3, 
        &quot;model&quot;: &quot;Vendedores.vendedor&quot;, 
        &quot;fields&quot;: {}
    }, 
    {
        &quot;pk&quot;: 4, 
        &quot;model&quot;: &quot;Vendedores.vendedor&quot;, 
        &quot;fields&quot;: {}
    }
]
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Espero me puedan ayudar con este problema, saludos.&lt;/p&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://pybonacci.wordpress.com/?p=196
            </guid>
            <title>
                Pybonacci: Ecuaciones no lineales: m&amp;#233;todo de bisecci&amp;#243;n y m&amp;#233;todo de Newton en Python
            </title>
            <pubDate>
                Wed, 18 Apr 2012 18:53:50 GMT
            </pubDate>
            <link>
                http://pybonacci.wordpress.com/2012/04/18/ecuaciones-no-lineales-metodo-de-biseccion-y-metodo-de-newton-en-python/
            </link>
            <description>
                &lt;p&gt;En este art&amp;#237;culo vamos a ver c&amp;#243;mo implementar en Python el&amp;#160;&lt;strong&gt;m&amp;#233;todo de bisecci&amp;#243;n&lt;/strong&gt;&amp;#160;y el&amp;#160;&lt;strong&gt;m&amp;#233;todo de Newton&lt;/strong&gt;, dos m&amp;#233;todos iterativos cl&amp;#225;sicos para hallar ra&amp;#237;ces de ecuaciones no lineales de la forma&amp;#160;&lt;img alt=&quot;f(x) = 0&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=f%28x%29+%3D+0&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;f(x) = 0&quot; /&gt;, con&amp;#160;&lt;img alt=&quot;f: [a, b] &amp;#92;longrightarrow &amp;#92;mathbb{R}&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=f%3A+%5Ba%2C+b%5D+%5Clongrightarrow+%5Cmathbb%7BR%7D&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;f: [a, b] &amp;#92;longrightarrow &amp;#92;mathbb{R}&quot; /&gt;&amp;#160;y&amp;#160;&lt;img alt=&quot;f &amp;#92;in C^1([a, b])&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=f+%5Cin+C%5E1%28%5Ba%2C+b%5D%29&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;f &amp;#92;in C^1([a, b])&quot; /&gt;. Estos m&amp;#233;todos y muchos otros m&amp;#225;s refinados est&amp;#225;n ya implementados en multitud de bibliotecas muy utilizadas, sin ir m&amp;#225;s lejos en el m&amp;#243;dulo&amp;#160;&lt;a href=&quot;http://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html#root-finding&quot;&gt;&lt;code&gt;optimize&lt;/code&gt;&lt;/a&gt;&amp;#160;del paquete Scipy (&lt;a href=&quot;http://docs.scipy.org/doc/scipy/reference/optimize.html#root-finding&quot;&gt;referencia&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Crearemos un m&amp;#243;dulo&amp;#160;&lt;code&gt;ceros.py&lt;/code&gt;&amp;#160;en el que incluiremos los dos m&amp;#233;todos que vamos a desarrollar aqu&amp;#237;, y as&amp;#237; veremos un ejemplo de c&amp;#243;digo limpio y f&amp;#225;cilmente reutilizable.&lt;/p&gt;
&lt;h2&gt;M&amp;#243;dulo&amp;#160;&lt;code&gt;ceros.py&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Vamos a ver la anatom&amp;#237;a de un m&amp;#243;dulo en Python. Este es el c&amp;#243;digo del archivo:&lt;/p&gt;
&lt;p&gt;&lt;span id=&quot;more-196&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
# -*- coding: utf-8 -*-

&amp;quot;&amp;quot;&amp;quot;B&amp;#250;squeda de ra&amp;#237;ces

Este m&amp;#243;dulo contiene m&amp;#233;todos para la b&amp;#250;squeda de ra&amp;#237;ces de ecuaciones de la
forma f(x) = 0, con f funci&amp;#243;n real de variable real, continua y de derivada
continua.

&amp;quot;&amp;quot;&amp;quot;

def biseccion():
    &amp;quot;&amp;quot;&amp;quot;M&amp;#233;todo de bisecci&amp;#243;n&amp;quot;&amp;quot;&amp;quot;
    pass

def newton():
    &amp;quot;&amp;quot;&amp;quot;M&amp;#233;todo de Newton&amp;quot;&amp;quot;&amp;quot;
    pass
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Analicemos el c&amp;#243;digo:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;La primera l&amp;#237;nea es fundamental en Python 2 si vamos a usar caracteres que se salen de ASCII. En ella especificamos que la codificaci&amp;#243;n sea UTF-8, como viene recogido en la&amp;#160;&lt;a href=&quot;http://www.python.org/dev/peps/pep-0263/&quot; title=&quot;PEP 263 -- Defining Python Source Code Encodings&quot;&gt;PEP 263&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;La l&amp;#237;nea entre triples comillas dobles es lo que se llama&amp;#160;&lt;em&gt;docstring&lt;/em&gt;&amp;#160;o cadena de documentaci&amp;#243;n del m&amp;#243;dulo, y siempre es una cadena que se pone al principio del archivo, como viene especificado en la&amp;#160;&lt;a href=&quot;http://www.python.org/dev/peps/pep-0257/&quot; title=&quot;PEP 257 -- Docstring Conventions - Python&quot;&gt;PEP 257&lt;/a&gt;. Lo de usar triples comillas nos aseguramos de que podemos incluir saltos de l&amp;#237;nea.&lt;/li&gt;
&lt;li&gt;Definimos dos funciones, tambi&amp;#233;n con su&amp;#160;&lt;em&gt;docstring&lt;/em&gt;. La palabra clave&amp;#160;&lt;code&gt;pass&lt;/code&gt;&amp;#160;se utiliza para que cuadre el sangrado del c&amp;#243;digo: no hace nada.&lt;/li&gt;
&lt;li&gt;Las convenciones en cuanto a espacios, longitud de las l&amp;#237;neas, etc. est&amp;#225;n definidas en la&amp;#160;&lt;a href=&quot;http://www.python.org/dev/peps/pep-0008/&quot; title=&quot;PEP 8 -- Style Guide for Python Code&quot;&gt;PEP 8&lt;/a&gt;, que viene a ser como el manual de estilo oficial para programas en Python. Puedes comprobar si tu c&amp;#243;digo se adhiere a esta convenci&amp;#243;n con la herramienta&amp;#160;&lt;a href=&quot;http://pypi.python.org/pypi/pep8/0.6.1&quot; title=&quot;pep8 en el PyPI&quot;&gt;pep8&lt;/a&gt;&amp;#160;disponible en el &amp;#205;ndice de Paquetes de Python (PyPI).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Para utilizar este m&amp;#243;dulo, simplemente lenzar&amp;#237;amos un int&amp;#233;rprete Python en la carpeta donde est&amp;#233; el archivo&amp;#160;&lt;code&gt;ceros.py&lt;/code&gt;&amp;#160;y escribir&amp;#237;amos:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
&amp;gt;&amp;gt;&amp;gt; import ceros
&amp;gt;&amp;gt;&amp;gt; dir(ceros)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'biseccion', 'newton']
&amp;gt;&amp;gt;&amp;gt; print ceros.__doc__
B&amp;#250;squeda de ra&amp;#237;ces

Este m&amp;#243;dulo contiene m&amp;#233;todos para la b&amp;#250;squeda de ra&amp;#237;ces de ecuaciones de la
forma f(x) = 0, con f funci&amp;#243;n real de variable real, continua y de derivada
continua.
&amp;gt;&amp;gt;&amp;gt; print ceros.biseccion
&amp;lt;function biseccion at 0x7fc17efb5668&amp;gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Ahora no hay m&amp;#225;s que&amp;#160;&lt;em&gt;implementar&lt;/em&gt;&amp;#160;estos m&amp;#233;todos.&lt;/p&gt;
&lt;h2&gt;M&amp;#233;todo de la bisecci&amp;#243;n&lt;/h2&gt;
&lt;h3&gt;Descripci&amp;#243;n y algoritmo&lt;/h3&gt;
&lt;p&gt;El&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/M%C3%A9todo_de_bisecci%C3%B3n&quot; title=&quot;M&amp;#233;todo de bisecci&amp;#243;n&quot;&gt;m&amp;#233;todo de bisecci&amp;#243;n&lt;/a&gt;&amp;#160;es un m&amp;#233;todo geom&amp;#233;tricamente muy intuitivo: partiendo de un intervalo&amp;#160;&lt;img alt=&quot;[a, b]&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%5Ba%2C+b%5D&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;[a, b]&quot; /&gt;&amp;#160;tal que&amp;#160;&lt;img alt=&quot;f(a) f(b) &amp;lt; 0&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=f%28a%29+f%28b%29+%3C+0&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;f(a) f(b) &amp;lt; 0&quot; /&gt;&amp;#160;(es decir: la funci&amp;#243;n cambia de signo en el intervalo), se va dividiendo en dos generando una&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Principio_de_los_intervalos_encajados&quot;&gt;sucesi&amp;#243;n de intervalos encajados&lt;/a&gt;&amp;#160;hasta que se converge con la precisi&amp;#243;n deseada a la ra&amp;#237;z de la ecuaci&amp;#243;n que, como asegura el&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/Teorema_del_valor_intermedio#Teorema_de_Bolzano&quot; title=&quot;Teorema de Bolzano&quot;&gt;teorema de Bolzano&lt;/a&gt;, tiene que existir; es decir, el&amp;#160;&lt;img alt=&quot;&amp;#92;alpha &amp;#92;in ]a, b[&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%5Calpha+%5Cin+%5Da%2C+b%5B&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;&amp;#92;alpha &amp;#92;in ]a, b[&quot; /&gt; tal que&amp;#160;&lt;img alt=&quot;f(&amp;#92;alpha) = 0&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=f%28%5Calpha%29+%3D+0&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;f(&amp;#92;alpha) = 0&quot; /&gt;.&lt;/p&gt;
&lt;p&gt;El algoritmo del m&amp;#233;todo de bisecci&amp;#243;n ser&amp;#237;a el siguiente:&lt;/p&gt;
&lt;blockquote&gt;
&lt;ol start=&quot;0&quot;&gt;
&lt;li&gt;Sean&amp;#160;&lt;img alt=&quot;f&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=f&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;f&quot; /&gt;,&amp;#160;&lt;img alt=&quot;a&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=a&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;a&quot; /&gt;&amp;#160;y&amp;#160;&lt;img alt=&quot;b&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=b&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;b&quot; /&gt;.
&lt;ol&gt;
&lt;li&gt;Sea&amp;#160;&lt;img alt=&quot;c &amp;#92;leftarrow &amp;#92;frac{a + b}{2}&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=c+%5Cleftarrow+%5Cfrac%7Ba+%2B+b%7D%7B2%7D&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;c &amp;#92;leftarrow &amp;#92;frac{a + b}{2}&quot; /&gt;.&lt;/li&gt;
&lt;li&gt;Si&amp;#160;&lt;img alt=&quot;f(c) = 0&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=f%28c%29+%3D+0&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;f(c) = 0&quot; /&gt;, terminar.&lt;/li&gt;
&lt;li&gt;Si&amp;#160;&lt;img alt=&quot;f(c) f(a) &amp;lt; 0&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=f%28c%29+f%28a%29+%3C+0&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;f(c) f(a) &amp;lt; 0&quot; /&gt;, entonces&amp;#160;&lt;img alt=&quot;b &amp;#92;leftarrow c&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=b+%5Cleftarrow+c&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;b &amp;#92;leftarrow c&quot; /&gt;&amp;#160;y volver al paso 1.&lt;/li&gt;
&lt;li&gt;Si no, entonces&amp;#160;&lt;img alt=&quot;a &amp;#92;leftarrow c&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=a+%5Cleftarrow+c&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;a &amp;#92;leftarrow c&quot; /&gt;&amp;#160;y volver al paso 1.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;p&gt;Este m&amp;#233;todo, aunque es lento,&amp;#160;&lt;strong&gt;tiene convergencia garantizada&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;M&amp;#233;todo de bisecci&amp;#243;n en Python&lt;/h3&gt;
&lt;p&gt;A la vista del algoritmo anterior, ya podemos implementar el m&amp;#233;todo de bisecci&amp;#243;n en Python. Nos vamos a saltar la parte de escribir el pseudoc&amp;#243;digo.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Nota&lt;/em&gt;&lt;/strong&gt;: Cambiado por sugerencia de David para evitar errores de precisi&amp;#243;n.&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
import numpy as np

def biseccion(f, a, b, tol=1.0e-6):
    &amp;quot;&amp;quot;&amp;quot;M&amp;#233;todo de bisecci&amp;#243;n

    Halla una ra&amp;#237;z de la funci&amp;#243;n f en el intervalo [a, b] mediante el m&amp;#233;todo
    de bisecci&amp;#243;n.

    Argumentos
    ----------
    f - Funci&amp;#243;n, debe ser tal que f(a) f(b) &amp;lt; 0
    a - Extremo inferior del intervalo
    b - Extremo superior del intervalo
    tol (opcional) - Cota para el error absoluto de la x

    Devuelve
    --------
    x - Ra&amp;#237;z de f en [a, b]

    Excepciones
    -----------
    ValueError - Intervalo mal definido, la funci&amp;#243;n no cambia de signo en el
                 intervalo o cota no positiva

    Ejemplos
    --------
    &amp;gt;&amp;gt;&amp;gt; def f(x): return x ** 2 - 1
    ...
    &amp;gt;&amp;gt;&amp;gt; biseccion(f, 0, 2)
    1.0
    &amp;gt;&amp;gt;&amp;gt; biseccion(f, 0, 5)
    1.000000238418579
    &amp;gt;&amp;gt;&amp;gt; biseccion(f, -2, 2)
    Traceback (most recent call last):
        File &amp;quot;&amp;lt;stdin&amp;gt;&amp;quot;, line 1, in &amp;lt;module&amp;gt;
        File &amp;quot;ceros.py&amp;quot;, line 35, in biseccion
        raise ValueError(&amp;quot;La funci&amp;#243;n debe cambiar de signo en el intervalo&amp;quot;)
    ValueError: La funci&amp;#243;n debe cambiar de signo en el intervalo
    &amp;gt;&amp;gt;&amp;gt; biseccion(f, -3, 0, tol=1.0e-12)
    -1.0000000000004547

    &amp;quot;&amp;quot;&amp;quot;
    if a &amp;gt; b:
        raise ValueError(&amp;quot;Intervalo mal definido&amp;quot;)
    if f(a) * f(b) &amp;gt;= 0.0:
        raise ValueError(&amp;quot;La funci&amp;#243;n debe cambiar de signo en el intervalo&amp;quot;)
    if tol &amp;lt;= 0:
        raise ValueError(&amp;quot;La cota de error debe ser un n&amp;#250;mero positivo&amp;quot;)
    x = (a + b) / 2.0
    while True:
        if b - a &amp;lt; tol:
            return x
        # Utilizamos la funci&amp;#243;n signo para evitar errores de precisi&amp;#243;n
        elif np.sign(f(a)) * np.sign(f(x)) &amp;lt; 0:
            b = x
        else:
            a = x
        x = (a + b) / 2.0
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Vamos a se&amp;#241;alar algunas cosas:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Como se puede observar, el c&amp;#243;digo se parece bastante al algoritmo.&lt;/li&gt;
&lt;li&gt;Podemos pasar una funci&amp;#243;n como argumento sin ning&amp;#250;n esfuerzo.&lt;/li&gt;
&lt;li&gt;Hemos incluido en la documentaci&amp;#243;n informaci&amp;#243;n sobre los argumentos que recibe la funci&amp;#243;n, de manera que si escribimos en el int&amp;#233;rprete&lt;code&gt;help(ceros.biseccion)&lt;/code&gt;&amp;#160;podremos consultarla.&lt;/li&gt;
&lt;li&gt;No he incluido un n&amp;#250;mero m&amp;#225;ximo de iteraciones: fijada una precisi&amp;#243;n, el m&amp;#233;todo converger&amp;#225; siempre.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Por &amp;#250;ltimo, n&amp;#243;tese que el programa produce un error si el l&amp;#237;mite inferior de intervalo es mayor que el l&amp;#237;mite superior, si la funci&amp;#243;n no cambia de signo o si la cota de error es un n&amp;#250;mero negativo. Python hace muy sencillas este tipo de construcciones: se denomina&amp;#160;&lt;a href=&quot;http://docs.python.org/tutorial/errors.html#handling-exceptions&quot; title=&quot;Manejo de excepciones&quot;&gt;manejo de excepciones&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Pod&amp;#237;amos haber tomado la decisi&amp;#243;n de no incluir este manejo de errores, y dejar que el programa falle inesperadamente si el usuario hace &amp;#171;cosas raras&amp;#187;. Esto que lo decida cada uno.&lt;/p&gt;
&lt;p&gt;Para gestionar los errores que se pueden producir, utilizamos el bloque &lt;code&gt;try...except&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
try:
    biseccion(f, a, b)
except ValueError:
    pass  # Este bloque se ejecuta si se produce un error
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Gracias a esta caracter&amp;#237;stica de Python podemos evitar cosas como que una divisi&amp;#243;n por cero mate al programa, por ejemplo.&lt;/p&gt;
&lt;h2&gt;M&amp;#233;todo de Newton&lt;/h2&gt;
&lt;h3&gt;Descripci&amp;#243;n y algoritmo&lt;/h3&gt;
&lt;p&gt;El&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/M%C3%A9todo_de_Newton&quot; title=&quot;M&amp;#233;todo de Newton&quot;&gt;m&amp;#233;todo de Newton&lt;/a&gt;&amp;#160;o m&amp;#233;todo de Newton-Raphson linealiza la funci&amp;#243;n a cada paso utilizando su derivada, que se debe proporcionar como argumento, para hallar la ra&amp;#237;z de la ecuaci&amp;#243;n en las proximidades de un punto inicial&amp;#160;&lt;img alt=&quot;x_0&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=x_0&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;x_0&quot; /&gt;. Este m&amp;#233;todo puede no converger, pero si el punto inicial est&amp;#225; lo suficientemente pr&amp;#243;ximo a la ra&amp;#237;z, la convergencia ser&amp;#225; muy r&amp;#225;pida.&lt;/p&gt;
&lt;p&gt;El algoritmo del m&amp;#233;todo de Newton es este:&lt;/p&gt;
&lt;blockquote&gt;
&lt;ol start=&quot;0&quot;&gt;
&lt;li&gt;Sean&amp;#160;&lt;img alt=&quot;f&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=f&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;f&quot; /&gt;,&amp;#160;&lt;img alt=&quot;f&amp;#039;&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=f%27&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;f&amp;#039;&quot; /&gt;&amp;#160;y&amp;#160;&lt;img alt=&quot;x0&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=x0&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;x0&quot; /&gt;.&lt;/li&gt;
&lt;li&gt;Sea&amp;#160;&lt;img alt=&quot;x &amp;#92;leftarrow x_0&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=x+%5Cleftarrow+x_0&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;x &amp;#92;leftarrow x_0&quot; /&gt;.
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;Sea&amp;#160;&lt;img alt=&quot;x &amp;#92;leftarrow x - &amp;#92;frac{f(x)}{f&amp;#039;(x)}&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=x+%5Cleftarrow+x+-+%5Cfrac%7Bf%28x%29%7D%7Bf%27%28x%29%7D&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;x &amp;#92;leftarrow x - &amp;#92;frac{f(x)}{f&amp;#039;(x)}&quot; /&gt;.&lt;/li&gt;
&lt;li&gt;Si&amp;#160;&lt;img alt=&quot;f(x) = 0&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=f%28x%29+%3D+0&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;f(x) = 0&quot; /&gt;, terminar.&lt;/li&gt;
&lt;li&gt;Si no, volver al paso 2.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;h3&gt;M&amp;#233;todo de Newton en Python&lt;/h3&gt;
&lt;p&gt;Aqu&amp;#237;, debido a que el m&amp;#233;todo no tiene garantizada la convergencia, habr&amp;#225; que considerar un n&amp;#250;mero m&amp;#225;ximo de iteraciones y cotas de error tanto para la ra&amp;#237;z como para el valor de la funci&amp;#243;n.&lt;/p&gt;
&lt;p&gt;El c&amp;#243;digo ser&amp;#237;a este:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
def newton(f, df, x_0, maxiter=50, xtol=1.0e-6, ftol=1.0e-6):
    &amp;quot;&amp;quot;&amp;quot;M&amp;#233;todo de Newton

    Halla la ra&amp;#237;z de la funci&amp;#243;n f en el entorno de x_0 mediante el m&amp;#233;todo de
    Newton.

    Argumentos
    ----------
    f - Funci&amp;#243;n
    df - Funci&amp;#243;n, debe ser la funci&amp;#243;n derivada de f
    x_0 - Punto de partida del m&amp;#233;todo
    maxiter (opcional) - N&amp;#250;mero m&amp;#225;ximo de iteraciones
    xtol (opcional) - Cota para el error relativo para la ra&amp;#237;z
    ftol (opcional) - Cota para el valor de la funci&amp;#243;n

    Devuelve
    --------
    x - Ra&amp;#237;z de la ecuaci&amp;#243;n en el entorno de x_0

    Excepciones
    -----------
    RuntimeError - No hubo convergencia superado el n&amp;#250;mero m&amp;#225;ximo de
                   iteraciones
    ZeroDivisionError - La derivada se anul&amp;#243; en alg&amp;#250;n punto
    Exception - El valor de x se sale del dominio de definici&amp;#243;n de f

    Ejemplos
    --------
    &amp;gt;&amp;gt;&amp;gt; def f(x): return x ** 2 - 1
    ...
    &amp;gt;&amp;gt;&amp;gt; def df(x): return 2 * x
    ...
    &amp;gt;&amp;gt;&amp;gt; newton(f, df, 2)
    1.000000000000001
    &amp;gt;&amp;gt;&amp;gt; newton(f, df, 5)
    1.0
    &amp;gt;&amp;gt;&amp;gt; newton(f, df, 0)
    Traceback (most recent call last):
      File &amp;quot;&amp;lt;stdin&amp;gt;&amp;quot;, line 1, in &amp;lt;module&amp;gt;
      File &amp;quot;ceros.py&amp;quot;, line 102, in newton
        dx = -f(x) / df(x)  # &amp;#161;Aqu&amp;#237; se puede producir una divisi&amp;#243;n por cero!
    ZeroDivisionError: float division by zero

    &amp;quot;&amp;quot;&amp;quot;
    x = float(x_0)  # Se convierte a n&amp;#250;mero de coma flotante
    for i in xrange(maxiter):
        dx = -f(x) / df(x)  # &amp;#161;Aqu&amp;#237; se puede producir una divisi&amp;#243;n por cero!
                            # Tambi&amp;#233;n x puede haber quedado fuera del dominio
        x = x + dx
        if abs(dx / x) &amp;lt; xtol and abs(f(x)) &amp;lt; ftol:
            return x
    raise RuntimeError(&amp;quot;No hubo convergencia despu&amp;#233;s de {} \
                        iteraciones&amp;quot;.format(maxiter))
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Se deja como ejercicio (qu&amp;#233; placentero es decir esto) programar el&amp;#160;&lt;a href=&quot;http://es.wikipedia.org/wiki/M%C3%A9todo_de_la_secante&quot; title=&quot;M&amp;#233;todo de la secante&quot;&gt;m&amp;#233;todo de la secante&lt;/a&gt;&amp;#160;que se utilice como alternativa si no se dispone de la derivada de la funci&amp;#243;n.&lt;/p&gt;
&lt;p&gt;&amp;#161;Y con eso terminamos el art&amp;#237;culo de hoy! Espero que te haya resultado provechoso, no olvides comentar, retwittear y dem&amp;#225;s zarandajas &lt;img alt=&quot;:)&quot; class=&quot;wp-smiley&quot; src=&quot;http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif&quot; /&gt; &lt;/p&gt;
&lt;h2&gt;Referencias&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;RIVAS, Dami&amp;#225;n y V&amp;#193;ZQUEZ, Carlos.&amp;#160;&lt;em&gt;Elementos de C&amp;#225;lculo Num&amp;#233;rico&lt;/em&gt;. ADI, 2010.&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;Filed under: &lt;a href=&quot;http://pybonacci.wordpress.com/category/basico/&quot;&gt;B&amp;#225;sico&lt;/a&gt; Tagged: &lt;a href=&quot;http://pybonacci.wordpress.com/tag/biseccion/&quot;&gt;biseccion&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/ecuaciones-no-lineales/&quot;&gt;ecuaciones no lineales&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/newton/&quot;&gt;newton&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/python/&quot;&gt;python&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gocomments/pybonacci.wordpress.com/196/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/comments/pybonacci.wordpress.com/196/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godelicious/pybonacci.wordpress.com/196/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/delicious/pybonacci.wordpress.com/196/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gofacebook/pybonacci.wordpress.com/196/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/facebook/pybonacci.wordpress.com/196/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gotwitter/pybonacci.wordpress.com/196/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/twitter/pybonacci.wordpress.com/196/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gostumble/pybonacci.wordpress.com/196/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/stumble/pybonacci.wordpress.com/196/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godigg/pybonacci.wordpress.com/196/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/digg/pybonacci.wordpress.com/196/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/goreddit/pybonacci.wordpress.com/196/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/reddit/pybonacci.wordpress.com/196/&quot; /&gt;&lt;/a&gt; &lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://stats.wordpress.com/b.gif?host=pybonacci.wordpress.com&amp;#038;blog=33759577&amp;#038;post=196&amp;#038;subd=pybonacci&amp;#038;ref=&amp;#038;feed=1&quot; width=&quot;1&quot; /&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://python.majibu.org/preguntas/1431/problema-feed-rss-django
            </guid>
            <title>
                python majibu: Problema Feed Rss Django
            </title>
            <pubDate>
                Wed, 18 Apr 2012 00:11:54 GMT
            </pubDate>
            <link>
                http://python.majibu.org/preguntas/1431/problema-feed-rss-django
            </link>
            <description>
                &lt;p&gt;Estoy creando un feed rss y me estoy basando en [&lt;a href=&quot;http://django.es/blog/crear-feeds-con-django/&quot;&gt;1&lt;/a&gt;]. He realizado todo pero me manda este error :&lt;/p&gt;
&lt;table class=&quot;codehilitetable&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;linenos&quot;&gt;&lt;div class=&quot;linenodiv&quot;&gt;&lt;pre&gt;1
2&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;ImproperlyConfigured&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;at&lt;/span&gt; &lt;span class=&quot;sr&quot;&gt;/feeds/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;blog&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Give&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;your&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Videos&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;get_absolute_url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;define&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;an&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_link&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;method&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;your&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Feed&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;He encontrado algo parecido a mi error en [&lt;a href=&quot;http://groups.google.com/group/django-users/browse_thread/thread/f40be0b19cf565b?pli=1&quot;&gt;2&lt;/a&gt;], al parecer me hac&amp;#237;a falta los archivos :&lt;/p&gt;
&lt;table class=&quot;codehilitetable&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;linenos&quot;&gt;&lt;div class=&quot;linenodiv&quot;&gt;&lt;pre&gt;1
2
3
4
5&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;blog_title&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;html&lt;/span&gt; 
&lt;span class=&quot;p&quot;&gt;{{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;obj&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}}&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;blog_description&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;html&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;obj&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Me bas&amp;#233; en esta p&amp;#225;gina [&lt;a href=&quot;http://www.andrlik.org/writing/2007/aug/03/fun-with-django-feeds/&quot;&gt;3&lt;/a&gt;], pero sigo teniendo el mismo error. Dejo mis archivos:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;feeds.py&lt;/strong&gt;&lt;/p&gt;
&lt;table class=&quot;codehilitetable&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;linenos&quot;&gt;&lt;div class=&quot;linenodiv&quot;&gt;&lt;pre&gt; 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;django.contrib.syndication.feeds&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Feed&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;kukulkan.control.models&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Videos&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;EntradaFeed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Feed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Mi Blog'&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;link&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;a href=&quot;http://www.mi_proyecto.com/blog/'&quot;&gt;http://www.mi_proyecto.com/blog/'&lt;/a&gt;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Descripcion de la tematica del blog.'&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;c&quot;&gt;# elementos del feed&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Videos&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;objects&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order_by&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;-fecha&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;item_pubdate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fecha&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;item_author_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;c&quot;&gt;# nombre del autor de cada elemento del feed&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;titulo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;urls.py&lt;/strong&gt;&lt;/p&gt;
&lt;table class=&quot;codehilitetable&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;linenos&quot;&gt;&lt;div class=&quot;linenodiv&quot;&gt;&lt;pre&gt;1
2
3
4
5
6
7&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;div class=&quot;codehilite&quot;&gt;&lt;pre&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;kukulkan.control.feeds&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EntradaFeed&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;feeds&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;'blog'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EntradaFeed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;urlpatterns&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;patterns&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;r'^feeds/(?P&amp;lt;url&amp;gt;.*)/$'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'django.contrib.syndication.views.feed'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'feed_dict'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;feeds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}),&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;No se que me falta hacer para que no me arroje este error&lt;/p&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://pybonacci.wordpress.com/?p=169
            </guid>
            <title>
                Pybonacci: Ejemplo de uso de Basemap y NetCDF4
            </title>
            <pubDate>
                Sat, 14 Apr 2012 11:14:50 GMT
            </pubDate>
            <link>
                http://pybonacci.wordpress.com/2012/04/14/ejemplo-de-uso-de-basemap-y-netcdf4/
            </link>
            <description>
                &lt;p&gt;Continuando lo que ense&amp;#241;&amp;#243; Juanlu en la anterior entrada vamos a mostrar l&amp;#237;neas de nivel y temperatura del aire en la superficie, en este caso la presi&amp;#243;n al nivel del mar del d&amp;#237;a 01 de enero de 2012 a las 00.00 UTC seg&amp;#250;n los datos extra&amp;#237;dos del &lt;a href=&quot;http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanalysis.html&quot;&gt;rean&amp;#225;lisis NCEP/NCAR&lt;/a&gt;, sobre un mapa con la ayuda de la librer&amp;#237;a &lt;a href=&quot;http://matplotlib.github.com/basemap/&quot;&gt;Basemap&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Como los datos del rean&amp;#225;lisis NCEP/NCAR vienen en formato &lt;a href=&quot;http://www.unidata.ucar.edu/software/netcdf/&quot;&gt;netCDF&lt;/a&gt; usaremos la librer&amp;#237;a &lt;a href=&quot;http://code.google.com/p/netcdf4-python/&quot;&gt;netcdf4-python&lt;/a&gt;. El formato netCDF es un est&amp;#225;ndar abierto y es ampliamente usado en temas de ciencias de la tierra, atm&amp;#243;sfera, climatolog&amp;#237;a, meteorolog&amp;#237;a,&amp;#8230; No es estrictamente necesario usar netcdf4-python para acceder a ficheros netCDF puesto que desde &lt;a href=&quot;http://www.scipy.org/doc/api_docs/SciPy.io.netcdf.html&quot;&gt;scipy ten&amp;#233;is esta funcionalidad&lt;/a&gt;. Pero bueno, yo uso esta por una serie de ventajas que veremos otro d&amp;#237;a.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;En la presente entrada se ha usado python 2.7.2, numpy 1.6.1, matplotlib 1.1.0, netCDF4 0.9.7 y Basemap 1.0.2.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Primero de todo vamos a importar todo lo que necesitamos:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
## Importamos las librer&amp;#237;as que nos hacen falta
import numpy as np
import netCDF4 as nc
import matplotlib.pyplot as plt
from mpl_toolkits import basemap as bm
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Los ficheros netCDF de presi&amp;#243;n al nivel del mar y de Temperatura del aire de la superficie los pod&amp;#233;is descargar de &lt;a href=&quot;http://www.esrl.noaa.gov/psd/cgi-bin/GrADS.pl?dataset=NCEP+Reanalysis+Surface+Level&amp;amp;DB_did=3&amp;amp;file=%2FDatasets%2Fncep.reanalysis%2Fsurface%2Fslp.1948.nc+slp.%25y4.nc+93912&amp;amp;variable=slp&amp;amp;DB_vid=30&amp;amp;DB_tid=33529&amp;amp;units=Pascals&amp;amp;longstat=Individual+Obs&amp;amp;DB_statistic=Individual+Obs&amp;amp;stat=&amp;amp;lat-begin=25N&amp;amp;lat-end=80.00N&amp;amp;lon-begin=20.00W&amp;amp;lon-end=60E&amp;amp;dim0=time&amp;amp;year_begin=2012&amp;amp;mon_begin=Jan&amp;amp;day_begin=1&amp;amp;hour_begin=00+Z&amp;amp;year_end=2012&amp;amp;mon_end=Jan&amp;amp;day_end=1&amp;amp;hour_end=00+Z&amp;amp;X=lon&amp;amp;Y=lat&amp;amp;output=file&amp;amp;bckgrnd=black&amp;amp;use_color=on&amp;amp;fill=lines&amp;amp;cint=&amp;amp;range1=&amp;amp;range2=&amp;amp;scale=100&amp;amp;submit=Create+Plot+or+Subset+of+Data&quot;&gt;aqu&amp;#237;&lt;/a&gt; y &lt;a href=&quot;http://www.esrl.noaa.gov/psd/cgi-bin/GrADS.pl?dataset=NCEP+Reanalysis+Surface+Level&amp;amp;DB_did=3&amp;amp;file=%2FDatasets%2Fncep.reanalysis%2Fsurface%2Fair.sig995.1948.nc+air.sig995.%25y4.nc+93912&amp;amp;variable=air&amp;amp;DB_vid=20&amp;amp;DB_tid=33529&amp;amp;units=degK&amp;amp;longstat=Individual+Obs&amp;amp;DB_statistic=Individual+Obs&amp;amp;stat=&amp;amp;lat-begin=25N&amp;amp;lat-end=80.00N&amp;amp;lon-begin=20.00W&amp;amp;lon-end=60E&amp;amp;dim0=time&amp;amp;year_begin=2012&amp;amp;mon_begin=Jan&amp;amp;day_begin=1&amp;amp;hour_begin=00+Z&amp;amp;year_end=2012&amp;amp;mon_end=Jan&amp;amp;day_end=1&amp;amp;hour_end=00+Z&amp;amp;X=lon&amp;amp;Y=lat&amp;amp;output=file&amp;amp;bckgrnd=black&amp;amp;use_color=on&amp;amp;fill=lines&amp;amp;cint=&amp;amp;range1=&amp;amp;range2=&amp;amp;scale=100&amp;amp;submit=Create+Plot+or+Subset+of+Data&quot;&gt;aqu&amp;#237;&lt;/a&gt;, respectivamente. Ver&amp;#233;is un enlace que pone &amp;#8216;FTP a copy of the file&amp;#8217;, lo pinch&amp;#225;is y guard&amp;#225;is en el mismo sitio donde teng&amp;#225;is el script que estamos haciendo en la presente entrada.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;Una vez que tenemos los ficheros los podemos abrir usando la librer&amp;#237;a netCDF4-python:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
## Abrimos los ficheros de datos,
## el nombre de los ficheros lo tendr&amp;#233;is que cambiar
## con el nombre de los ficheros que os hab&amp;#233;is descargado
slp = nc.Dataset('X83.34.8.250.104.4.18.19.nc') #slp por 'sea level pressure'
tsfc = nc.Dataset('X83.34.8.250.104.4.15.31.nc') #tsfc 'por temperature at surface'
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span id=&quot;more-169&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;p&gt;Para saber las variables que tenemos en cada fichero netCDF podemos escribir lo siguiente:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
## Qu&amp;#233; variables hay dentro de cada netCDF
print slp.variables
print tsfc.variables
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;El output que veremos para slp ser&amp;#225;:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
OrderedDict([(u'lat', &amp;lt;netCDF4.Variable object at 0x05F72FA8&amp;gt;), (u'lon', &amp;lt;netCDF4.Variable object at 0x0603C198&amp;gt;), (u'time', &amp;lt;netCDF4.Variable object at 0x0603C150&amp;gt;), (u'slp', &amp;lt;netCDF4.Variable object at 0x060A1FA8&amp;gt;)])
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;De la misma forma, para tsfc tendremos:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
OrderedDict([(u'lat', &amp;lt;netCDF4.Variable object at 0x060AE108&amp;gt;), (u'lon', &amp;lt;netCDF4.Variable object at 0x060AE030&amp;gt;), (u'time', &amp;lt;netCDF4.Variable object at 0x060AE078&amp;gt;), (u'air', &amp;lt;netCDF4.Variable object at 0x060AE150&amp;gt;)])
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Nos interesa acceder a las variables &amp;#8216;slp&amp;#8217;, &amp;#8216;air&amp;#8217;, &amp;#8216;lat&amp;#8217;&amp;#160; y &amp;#8216;lon&amp;#8217;. Las dos &amp;#250;ltimas variables son las mismas tanto en slp como en tsfc ya que nos hemos descargado el campo de presi&amp;#243;n y temperatura para la misma fecha y para la misma &amp;#225;rea. Por tanto, para acceder a los datos y poder dibujarlos hacemos lo siguiente:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
slpdata = slp.variables['slp'][:] #Obtenemos los datos en Pa
tsfcdata = tsfc.variables['air'][:] #Obtenemos los datos en &amp;#186;K
lat = slp.variables['lat'][:] #Obtenemos los datos en &amp;#186;
lon = slp.variables['lon'][:] #Obtenemos los datos en &amp;#186;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Los datos se han guardado en las variables slpdata, tsfcdata, lat y lon como numpy arrays. Para que la presi&amp;#243;n est&amp;#233; en hPa&amp;#160; o mb (hectopascales o milibares), la temperatura en &amp;#186;C y las longitudes vayan en una escala de -180&amp;#186; a 180&amp;#186; hacemos lo siguiente:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
slpdata = slpdata * 0.01
tsfcdata = tsfcdata - 273.15
lon[lon &amp;gt; 180] = lon - 360.
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Ahora creamos una instancia a Basemap:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
m = bm.Basemap(llcrnrlon = -20,
               llcrnrlat = 25,
               urcrnrlon = 60,
               urcrnrlat = 80,
               projection = 'mill')
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;En el anterior c&amp;#243;digo hemos puesto lo siguiente:&lt;/p&gt;
&lt;p&gt;|&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; llcrnrlon&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; longitud de la esquina inferior izquierda del dominio del mapa seleccionado.&lt;br /&gt;
|&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; llcrnrlat&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; latitud de la esquina inferior izquierda del dominio del mapa seleccionado.&lt;br /&gt;
|&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; urcrnrlon&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; longitud de la esquina superior derecha del dominio del mapa seleccionado.&lt;br /&gt;
|&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; urcrnrlat&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; latitud de la esquina superior derecha del dominio del mapa seleccionado.&lt;/p&gt;
&lt;p&gt;Para &lt;em&gt;projection&lt;/em&gt; hemos usado &lt;em&gt;mill&lt;/em&gt; que ser&amp;#225; para una proyecci&amp;#243;n &lt;a href=&quot;http://en.wikipedia.org/wiki/Miller_cylindrical_projection&quot;&gt;Miller cylindrical&lt;/a&gt;. Si quer&amp;#233;is ver todas las proyecciones disponibles pod&amp;#233;is escribir:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
print bm.supported_projections
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Y ver&amp;#233;is el siguiente output:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
aeqd&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Azimuthal Equidistant
poly&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Polyconic
gnom&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Gnomonic
moll&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Mollweide
tmerc&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Transverse Mercator
nplaea&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; North-Polar Lambert Azimuthal
gall&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Gall Stereographic Cylindrical
mill&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Miller Cylindrical
merc&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Mercator
stere&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Stereographic
npstere&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; North-Polar Stereographic
hammer&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Hammer
geos&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Geostationary
nsper&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Near-Sided Perspective
vandg&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; van der Grinten
laea&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Lambert Azimuthal Equal Area
mbtfpq&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; McBryde-Thomas Flat-Polar Quartic
sinu&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Sinusoidal
spstere&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; South-Polar Stereographic
lcc&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Lambert Conformal
npaeqd&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; North-Polar Azimuthal Equidistant
eqdc&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Equidistant Conic
cyl&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Cylindrical Equidistant
omerc&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Oblique Mercator
aea&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Albers Equal Area
spaeqd&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; South-Polar Azimuthal Equidistant
ortho&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Orthographic
cass&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Cassini-Soldner
splaea&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; South-Polar Lambert Azimuthal
robin&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Robinson
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Buscamos los valores x e y que representar&amp;#225;n a las latitudes y longitudes de la proyecci&amp;#243;n del mapa seleccionada:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
## Encontramos los valores x,y para el grid de la proyecci&amp;#243;n del mapa.
lon, lat = np.meshgrid(lon, lat)
x, y = m(lon, lat)
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Vamos a representar el campo de presiones en el mapa:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
fig=plt.figure(figsize=(8,6))
ax = fig.add_axes([0.05,0.05,0.9,0.85])
cs = m.contour(x,y,slpdata[0,:,:],np.arange(900,1100.,5.),colors='y',linewidths=1.25)
m.drawparallels(np.arange(0,360,10),labels=[1,1,0,0])
m.drawmeridians(np.arange(-180,180,10),labels=[0,0,0,1])
m.bluemarble()
plt.show()
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Este &amp;#250;ltimo c&amp;#243;digo mostrar&amp;#225; la siguiente figura:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://pybonacci.files.wordpress.com/2012/04/ejemplo_bluemarble.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-173&quot; height=&quot;500&quot; src=&quot;http://pybonacci.files.wordpress.com/2012/04/ejemplo_bluemarble.png?w=700&amp;amp;h=500&quot; title=&quot;Ejemplo_BlueMarble&quot; width=&quot;700&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;En el anterior mapa hemos mostrado las l&amp;#237;neas de nivel de la presi&amp;#243;n, hemos dibujado meridianos y paralelos y lo hemos representado con una proyecci&amp;#243;n cil&amp;#237;ndrica de Miller usando como fondo los datos &lt;a href=&quot;http://en.wikipedia.org/wiki/The_Blue_Marble&quot;&gt;Blue Marble de la NASA&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Ahora vamos a introducir tambi&amp;#233;n los datos de temperatura usando contourf (la f viene de fill, relleno y son contornos rellenados). Metemos lo siguiente en nuestro script:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
# create figure.
fig=plt.figure(figsize=(8,6))
ax = fig.add_axes([0.05,0.05,0.9,0.85])
cs = m.contour(x,y,slpdata[0,:,:],np.arange(900,1100.,5.),colors='k',linewidths=1.)
csf = m.contourf(x,y,tsfcdata[0,:,:],np.arange(-50,50.,2.))
m.drawcoastlines(linewidth=1.25, color='grey')
m.drawparallels(np.arange(0,360,10),labels=[1,1,0,0])
m.drawmeridians(np.arange(-180,180,10),labels=[0,0,0,1])
plt.show()
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Y obtenemos el siguiente resultado:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://pybonacci.files.wordpress.com/2012/04/ejemplo_p_y_t.png&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-176&quot; height=&quot;500&quot; src=&quot;http://pybonacci.files.wordpress.com/2012/04/ejemplo_p_y_t.png?w=700&amp;amp;h=500&quot; title=&quot;Ejemplo_P_y_T&quot; width=&quot;700&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Donde hemos representado la presi&amp;#243;n al nivel del mar (isol&amp;#237;neas en color negro), las temperaturas en superficie (contornos de color rellenos), las l&amp;#237;neas de costa (l&amp;#237;neas continuas grises), paralelos y meridianos.&lt;/p&gt;
&lt;p&gt;El script final quedar&amp;#237;a algo as&amp;#237;:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
## Importamos las librer&amp;#237;as que vamos a usar
import numpy as np
import netCDF4 as nc
import matplotlib.pyplot as plt
from mpl_toolkits import basemap as bm

## Abrimos los ficheros de datos
slp = nc.Dataset('X83.34.8.250.104.4.18.19.nc') #slp por 'sea level pressure'
tsfc = nc.Dataset('X83.34.8.250.104.4.15.31.nc') #tsfc 'por temperature at surface'slp.variables
print slp.variables
print tsfc.variables

slpdata = slp.variables['slp'][:] #Obtenemos los datos en Pa
tsfcdata = tsfc.variables['air'][:] #Obtenemos los datos en &amp;#186;K
lat = slp.variables['lat'][:] #Obtenemos los datos en &amp;#186;
lon = slp.variables['lon'][:] #Obtenemos los datos en &amp;#186;
slpdata = slpdata * 0.01
tsfcdata = tsfcdata - 273.15
lon[lon &amp;gt; 180] = lon - 360.

## Creamos una instancia a Basemap
m = bm.Basemap(llcrnrlon = -20,
               llcrnrlat = 25,
               urcrnrlon = 60,
               urcrnrlat = 80,
               projection = 'mill')
print bm.supported_projections

## Encontramos los valores x,y para el grid de la proyecci&amp;#243;n del mapa.
lon, lat = np.meshgrid(lon, lat)
x, y = m(lon, lat)

# Creamos la figura con P sobre fondo Blue Marble.
fig=plt.figure(figsize=(8,6))
ax = fig.add_axes([0.05,0.05,0.9,0.85])
cs = m.contour(x,y,slpdata[0,:,:],np.arange(900,1100.,5.),colors='y',linewidths=1.25)
m.drawparallels(np.arange(0,360,10),labels=[1,1,0,0])
m.drawmeridians(np.arange(-180,180,10),labels=[0,0,0,1])
m.bluemarble()
plt.show()

# Creamos la figura con P y T.
fig=plt.figure(figsize=(8,6))
ax = fig.add_axes([0.05,0.05,0.9,0.85])
cs = m.contour(x,y,slpdata[0,:,:],np.arange(900,1100.,5.),colors='k',linewidths=1.)
csf = m.contourf(x,y,tsfcdata[0,:,:],np.arange(-50,50.,2.))
m.drawcoastlines(linewidth=1.25, color='grey')
m.drawparallels(np.arange(0,360,10),labels=[1,1,0,0])
m.drawmeridians(np.arange(-180,180,10),labels=[0,0,0,1])
plt.show()
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Y eso es todo por hoy. En alg&amp;#250;n momento, siempre que el tiempo lo permita, veremos m&amp;#225;s en profundidad Basemap y Netcdf4-python.&lt;/p&gt;
&lt;p&gt;Saludos.&lt;/p&gt;
&lt;p&gt;P.D.: Lo de siempre, si encontr&amp;#225;is errores, quer&amp;#233;is criticar (constructivamente) mis bajas dotes como programador o quer&amp;#233;is aportar alguna cosa usad los comentarios.&lt;/p&gt;
&lt;br /&gt;Filed under: &lt;a href=&quot;http://pybonacci.wordpress.com/category/basico/&quot;&gt;B&amp;#225;sico&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/category/tutoriales/&quot;&gt;Tutoriales&lt;/a&gt; Tagged: &lt;a href=&quot;http://pybonacci.wordpress.com/tag/basemap/&quot;&gt;basemap&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/mapas/&quot;&gt;mapas&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/matplotlib/&quot;&gt;matplotlib&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/meteorologia/&quot;&gt;meteorolog&amp;#237;a&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/netcdf/&quot;&gt;netcdf&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/netcdf4-python/&quot;&gt;netcdf4-python&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/numpy/&quot;&gt;numpy&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/python/&quot;&gt;python&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gocomments/pybonacci.wordpress.com/169/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/comments/pybonacci.wordpress.com/169/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godelicious/pybonacci.wordpress.com/169/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/delicious/pybonacci.wordpress.com/169/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gofacebook/pybonacci.wordpress.com/169/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/facebook/pybonacci.wordpress.com/169/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gotwitter/pybonacci.wordpress.com/169/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/twitter/pybonacci.wordpress.com/169/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gostumble/pybonacci.wordpress.com/169/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/stumble/pybonacci.wordpress.com/169/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godigg/pybonacci.wordpress.com/169/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/digg/pybonacci.wordpress.com/169/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/goreddit/pybonacci.wordpress.com/169/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/reddit/pybonacci.wordpress.com/169/&quot; /&gt;&lt;/a&gt; &lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://stats.wordpress.com/b.gif?host=pybonacci.wordpress.com&amp;#038;blog=33759577&amp;#038;post=169&amp;#038;subd=pybonacci&amp;#038;ref=&amp;#038;feed=1&quot; width=&quot;1&quot; /&gt;
            </description>
        </item>
        <item>
            <guid isPermaLink="false">
                http://pybonacci.wordpress.com/?p=154
            </guid>
            <title>
                Pybonacci: Dibujando l&amp;#237;neas de nivel en Python con matplotlib
            </title>
            <pubDate>
                Fri, 13 Apr 2012 11:08:04 GMT
            </pubDate>
            <link>
                http://pybonacci.wordpress.com/2012/04/13/dibujando-lineas-de-nivel-en-python-con-matplotlib/
            </link>
            <description>
                &lt;h2&gt;Introducci&amp;#243;n&lt;/h2&gt;
&lt;p&gt;En este art&amp;#237;culo vamos a ver c&amp;#243;mo representar en Python&amp;#160;un mapa de &lt;em&gt;curvas de nivel&lt;/em&gt; o de &lt;em&gt;isol&amp;#237;neas&lt;/em&gt;, esto es, curvas que conectan&amp;#160;los puntos en los que una funci&amp;#243;n tiene un mismo valor constante,&amp;#160;utilizando NumPy y matplotlib. Los mapas de curvas de nivel (&amp;#171;contour lines&amp;#187; en ingl&amp;#233;s) son muy &amp;#250;tiles, porque ayudan a ver la informaci&amp;#243;n de una manera mucho m&amp;#225;s c&amp;#243;moda que las representaciones de superficies en tres dimensiones, por muy espectaculares que estas &amp;#250;ltimas puedan quedar. Un ejemplo muy cotidiano es el mapa de isobaras que nos dan en la predicci&amp;#243;n del tiempo como el que se ve en la imagen: los puntos que est&amp;#225;n sobre la misma l&amp;#237;nea est&amp;#225;n todos a la misma presi&amp;#243;n.&lt;/p&gt;
&lt;div class=&quot;wp-caption aligncenter&quot; id=&quot;attachment_156&quot; style=&quot;width: 458px;&quot;&gt;&lt;a href=&quot;http://pybonacci.files.wordpress.com/2012/04/2012041300006_ww_i1x0w006.gif&quot;&gt;&lt;img alt=&quot;Mapa de isobaras&quot; class=&quot; wp-image-156  &quot; height=&quot;263&quot; src=&quot;http://pybonacci.files.wordpress.com/2012/04/2012041300006_ww_i1x0w006.gif?w=448&amp;amp;h=263&quot; title=&quot;Mapa de isobaras&quot; width=&quot;448&quot; /&gt;&lt;/a&gt;&lt;p class=&quot;wp-caption-text&quot;&gt;Mapa HIRLAM-AEMET 0.16&amp;#176; de Superficie (Presi&amp;#243;n). V&amp;#225;lido para el viernes, 13 abril 2012 a las 08:00. &amp;#169; Agencia Estatal de Meteorolog&amp;#237;a.&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;&lt;span id=&quot;more-154&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;En este art&amp;#237;culo nos ce&amp;#241;iremos a funciones&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;f&amp;#92;!: D &amp;#92;longrightarrow &amp;#92;mathbb{R}, D &amp;#92;subset &amp;#92;mathbb{R}^2,&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=f%5C%21%3A+D+%5Clongrightarrow+%5Cmathbb%7BR%7D%2C+D+%5Csubset+%5Cmathbb%7BR%7D%5E2%2C&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;f&amp;#92;!: D &amp;#92;longrightarrow &amp;#92;mathbb{R}, D &amp;#92;subset &amp;#92;mathbb{R}^2,&quot; /&gt;&lt;/p&gt;
&lt;p&gt;es decir, funciones que est&amp;#225;n definidas en un conjunto del plano y que a cada punto del mismo le asignan un n&amp;#250;mero real. En el caso del ejemplo que hemos puesto, la funci&amp;#243;n estar&amp;#237;a definida (aceptando por un segundo que la Tierra es plana) en un conjunto del mapa que comprende la zona de la imagen y a cada punto le asigna el valor de presi&amp;#243;n atmosf&amp;#233;rica en dicho punto.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Para la siguiente entrada se ha usado python 2.7.2, numpy 1.6.1, scipy 0.9.0 y matplotlib 1.1.0.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;mallado&quot;&gt;Creaci&amp;#243;n del mallado&lt;/h2&gt;
&lt;p&gt;Vamos a representar el mapa de curvas de nivel de la funci&amp;#243;n&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;f(x, y) = &amp;#92;cos(-10 x y)+&amp;#92;sinh(x+y)-&amp;#92;log(&amp;#92;frac{3+x^2}{1+y^2}).&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=f%28x%2C+y%29+%3D+%5Ccos%28-10+x+y%29%2B%5Csinh%28x%2By%29-%5Clog%28%5Cfrac%7B3%2Bx%5E2%7D%7B1%2By%5E2%7D%29.&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;f(x, y) = &amp;#92;cos(-10 x y)+&amp;#92;sinh(x+y)-&amp;#92;log(&amp;#92;frac{3+x^2}{1+y^2}).&quot; /&gt;&lt;/p&gt;
&lt;p&gt;en el dominio &lt;img alt=&quot;D = [-3 / 2, 3 / 2] &amp;#92;times [-3 / 2, 3 / 2]&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=D+%3D+%5B-3+%2F+2%2C+3+%2F+2%5D+%5Ctimes+%5B-3+%2F+2%2C+3+%2F+2%5D&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;D = [-3 / 2, 3 / 2] &amp;#92;times [-3 / 2, 3 / 2]&quot; /&gt;. Me la acabo de inventar, y quedan las l&amp;#237;neas curiosas.&lt;/p&gt;
&lt;p&gt;Para empezar tenemos que&amp;#160;&lt;em&gt;discretizar&lt;/em&gt; este dominio: generaremos una malla o rejilla de puntos y evaluaremos la funci&amp;#243;n en cada uno de ellos. Para ello, utilizaremos la funci&amp;#243;n &lt;a href=&quot;http://docs.scipy.org/doc/numpy-1.6.0/reference/generated/numpy.meshgrid.html&quot;&gt;&lt;code&gt;meshgrid()&lt;/code&gt;&lt;/a&gt; de NumPy:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;$ ipython2
Python 2.7.2 (default, Jan 31 2012, 13:19:49)
Type &amp;quot;copyright&amp;quot;, &amp;quot;credits&amp;quot; or &amp;quot;license&amp;quot; for more information.

IPython 0.12 -- An enhanced Interactive Python.
?         -&amp;gt; Introduction and overview of IPython's features.
%quickref -&amp;gt; Quick reference.
help      -&amp;gt; Python's own help system.
object?   -&amp;gt; Details about 'object', use 'object??' for extra details.

In [1]: import numpy as np

In [2]: xx = np.linspace(-1.5, 1.5)

In [3]: yy = xx.copy()

In [4]: X, Y = np.meshgrid(xx, yy)

In [5]: X
Out[5]:
array([[-1.5       , -1.43877551, -1.37755102, ...,  1.37755102,
         1.43877551,  1.5       ],
       [-1.5       , -1.43877551, -1.37755102, ...,  1.37755102,
         1.43877551,  1.5       ],
       [-1.5       , -1.43877551, -1.37755102, ...,  1.37755102,
         1.43877551,  1.5       ],
       ...,
       [-1.5       , -1.43877551, -1.37755102, ...,  1.37755102,
         1.43877551,  1.5       ],
       [-1.5       , -1.43877551, -1.37755102, ...,  1.37755102,
         1.43877551,  1.5       ],
       [-1.5       , -1.43877551, -1.37755102, ...,  1.37755102,
         1.43877551,  1.5       ]])

In [6]: Y
Out[6]:
array([[-1.5       , -1.5       , -1.5       , ..., -1.5       ,
        -1.5       , -1.5       ],
       [-1.43877551, -1.43877551, -1.43877551, ..., -1.43877551,
        -1.43877551, -1.43877551],
       [-1.37755102, -1.37755102, -1.37755102, ..., -1.37755102,
        -1.37755102, -1.37755102],
       ...,
       [ 1.37755102,  1.37755102,  1.37755102, ...,  1.37755102,
         1.37755102,  1.37755102],
       [ 1.43877551,  1.43877551,  1.43877551, ...,  1.43877551,
         1.43877551,  1.43877551],
       [ 1.5       ,  1.5       ,  1.5       , ...,  1.5       ,
         1.5       ,  1.5       ]])
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;En primer lugar hemos creado dos vectores &lt;code&gt;xx&lt;/code&gt; e &lt;code&gt;yy&lt;/code&gt; donde hemos almacenado los dos intervalos, y despu&amp;#233;s hemos llamado a la funci&amp;#243;n &lt;code&gt;meshgrid(xx, yy)&lt;/code&gt; y nos ha devuelto dos arrays de dimensi&amp;#243;n 2: el primero de ellos var&amp;#237;a s&amp;#243;lo a lo largo de las columnas, y el segundo s&amp;#243;lo a lo largo de las filas. A los que vengan de MATLAB esto les parecer&amp;#225; obvio, pero el resto tal vez se est&amp;#233;n preguntando &amp;#191;por qu&amp;#233;? y &amp;#191;para qu&amp;#233;?&lt;/p&gt;
&lt;p&gt;Para entender por qu&amp;#233; esto es &amp;#250;til, es fundamental recordar que en NumPy las operaciones est&amp;#225;n &lt;strong&gt;vectorizadas&lt;/strong&gt;. Observa que si para cada fila &lt;code&gt;i&lt;/code&gt; y columna &lt;code&gt;j&lt;/code&gt; creamos el par &lt;img alt=&quot;(X_{ij}, Y_{ij})&quot; class=&quot;latex&quot; src=&quot;http://s0.wp.com/latex.php?latex=%28X_%7Bij%7D%2C+Y_%7Bij%7D%29&amp;amp;bg=ffffff&amp;amp;fg=1c1c1c&amp;amp;s=0&quot; title=&quot;(X_{ij}, Y_{ij})&quot; /&gt;, ya tenemos la rejilla de puntos creada y almacenada en una matriz &lt;em&gt;que tiene la misma dimensi&amp;#243;n que X e Y&lt;/em&gt;. Si ahora hici&amp;#233;semos&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
Z = np.cos(X ** 2 + Y ** 2)
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;en realidad ser&amp;#237;a como escribir&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
for i in range(len(X)):
    for j in range(len(Y)):
        Z[i, j] = np.cos(X[i, j] ** 2 + Y[i, j] ** 2)
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;y en el array &lt;em&gt;bidimensional&lt;/em&gt; Z tendr&amp;#237;amos los valores de la funci&amp;#243;n coseno &lt;em&gt;para cada punto de la malla&lt;/em&gt;. Esta forma abreviada de escribir el c&amp;#243;digo es la que se denomina &lt;strong&gt;vectorizada&lt;/strong&gt; y funciona porque X, Y y Z tienen la misma dimensi&amp;#243;n y el mismo tama&amp;#241;o. Es muy importante porque, adem&amp;#225;s de escribir menos c&amp;#243;digo, las operaciones se ejecutan &lt;strong&gt;&amp;#243;rdenes de magnitud&lt;/strong&gt; m&amp;#225;s deprisa.&lt;/p&gt;
&lt;p&gt;Dicho esto, justamente lo que queremos es la matriz Z donde almacenar el valor de nuestra funci&amp;#243;n para cada uno de los puntos de la malla:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [7]: from numpy import cos, sinh, log

In [8]: Z = cos(-10 * X * Y) + sinh(X + Y) - log((3 + X ** 2) / (1 + Y ** 2))

In [9]: Z
Out[9]:
array([[-11.37075265, -10.78189814,  -9.50784471, ...,  -0.77338623,
         -1.42327703,  -1.35287772],
       [-10.87372363,  -9.63560489,  -8.22976433, ...,   0.03672752,
         -0.77839121,  -1.39257702],
       [ -9.69207397,  -8.3221681 ,  -7.36241976, ...,   0.46710156,
          0.06684924,  -0.71210509],
       ...,
       [ -0.95761549,  -0.05567626,   0.46710156, ...,   8.29662289,
          8.33334108,   8.02235339],
       [ -1.51510252,  -0.77839121,   0.15925301, ...,   8.42574485,
          8.07882247,   7.96604409],
       [ -1.35287772,  -1.30075153,  -0.52787582, ...,   8.20658265,
          8.05786958,   8.66499721]])
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Ya tenemos la parte de c&amp;#225;lculo lista, y ahora s&amp;#243;lo queda representar.&lt;/p&gt;
&lt;h2&gt;Representaci&amp;#243;n de las l&amp;#237;neas de nivel&lt;/h2&gt;
&lt;p&gt;La biblioteca matplotlib ofrece dos funciones para representar curvas de nivel: &lt;a href=&quot;http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.contour&quot;&gt;&lt;code&gt;contour()&lt;/code&gt;&lt;/a&gt; y &lt;a href=&quot;http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.contourf&quot;&gt;&lt;code&gt;contourf()&lt;/code&gt;&lt;/a&gt;. La &amp;#250;nica diferencia entre las dos es que en la primera se representan s&amp;#243;lo las l&amp;#237;neas, y en la segunda se rellena el espacio entre ellas.&lt;/p&gt;
&lt;p&gt;Para obtener ayuda sobre estas funciones sin acudir a la documentaci&amp;#243;n, recuerda que en IPython podemos escribir&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [10]: import matplotlib.pyplot as plt

In [11]: plt.contour?
...
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Para crear la figura bastan dos l&amp;#237;neas:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [12]: plt.contour(X, Y, Z)
Out[12]:

In [13]: plt.show()
&lt;/pre&gt;&lt;/p&gt;
&lt;p style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://pybonacci.files.wordpress.com/2012/04/rare_contour.png&quot;&gt;&lt;img alt=&quot;Curvas de nivel&quot; class=&quot;aligncenter  wp-image-164&quot; height=&quot;336&quot; src=&quot;http://pybonacci.files.wordpress.com/2012/04/rare_contour.png?w=448&amp;amp;h=336&quot; title=&quot;Curvas de nivel&quot; width=&quot;448&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;E voil&amp;#224;! Sencillo como siempre &lt;img alt=&quot;:)&quot; class=&quot;wp-smiley&quot; src=&quot;http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif&quot; /&gt;  Incluso podemos rizar m&amp;#225;s el rizo:&lt;/p&gt;
&lt;p&gt;&lt;pre class=&quot;brush: python;&quot;&gt;
In [14]: cs1 = plt.contourf(X, Y, Z, 25)  # Pintamos 25 niveles con relleno

In [15]: cs2 = plt.contour(X, Y, Z, cs1.levels, colors='k')  # A&amp;#241;adimos bordes negros

In [16]: plt.show()
&lt;/pre&gt;&lt;/p&gt;
&lt;p style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://pybonacci.files.wordpress.com/2012/04/rare_contour_f.png&quot;&gt;&lt;img alt=&quot;Curvas de nivel con relleno&quot; class=&quot;aligncenter  wp-image-165&quot; height=&quot;336&quot; src=&quot;http://pybonacci.files.wordpress.com/2012/04/rare_contour_f.png?w=448&amp;amp;h=336&quot; title=&quot;Curvas de nivel con relleno&quot; width=&quot;448&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;La biblioteca matplotlib es enorme y da docenas de opciones para configurar la apariencia: colores, ejes&amp;#8230; es cuesti&amp;#243;n de bucear en la documentaci&amp;#243;n y experimentar.&lt;/p&gt;
&lt;p&gt;Espero que el art&amp;#237;culo os haya resultado &amp;#250;til, no olvid&amp;#233;is recomendar el art&amp;#237;culo y hacernos vuestras aportaciones en los comentarios. &amp;#161;Nos vemos pronto!&lt;/p&gt;
&lt;br /&gt;Filed under: &lt;a href=&quot;http://pybonacci.wordpress.com/category/basico/&quot;&gt;B&amp;#225;sico&lt;/a&gt; Tagged: &lt;a href=&quot;http://pybonacci.wordpress.com/tag/graficos/&quot;&gt;gr&amp;#225;ficos&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/matplotlib/&quot;&gt;matplotlib&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/numpy/&quot;&gt;numpy&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/python/&quot;&gt;python&lt;/a&gt;, &lt;a href=&quot;http://pybonacci.wordpress.com/tag/vectorizacion/&quot;&gt;vectorizaci&amp;#243;n&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gocomments/pybonacci.wordpress.com/154/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/comments/pybonacci.wordpress.com/154/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godelicious/pybonacci.wordpress.com/154/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/delicious/pybonacci.wordpress.com/154/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gofacebook/pybonacci.wordpress.com/154/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/facebook/pybonacci.wordpress.com/154/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gotwitter/pybonacci.wordpress.com/154/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/twitter/pybonacci.wordpress.com/154/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/gostumble/pybonacci.wordpress.com/154/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/stumble/pybonacci.wordpress.com/154/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/godigg/pybonacci.wordpress.com/154/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/digg/pybonacci.wordpress.com/154/&quot; /&gt;&lt;/a&gt; &lt;a href=&quot;http://feeds.wordpress.com/1.0/goreddit/pybonacci.wordpress.com/154/&quot; rel=&quot;nofollow&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://feeds.wordpress.com/1.0/reddit/pybonacci.wordpress.com/154/&quot; /&gt;&lt;/a&gt; &lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://stats.wordpress.com/b.gif?host=pybonacci.wordpress.com&amp;#038;blog=33759577&amp;#038;post=154&amp;#038;subd=pybonacci&amp;#038;ref=&amp;#038;feed=1&quot; width=&quot;1&quot; /&gt;
            </description>
        </item>
    </channel>
</rss>

