Python Tips

This is a compendium of things I often forget.

Numpy

   1 numpy.unravel_index(arr.argmax(),arr.shape)

where arr is an N-D array

Matplotlib

   1     clr = ['k','b','r','g']
   2     ls  = ['-','--','-.',':']

   1     from matplotlib.lines import Line2D
   2     for m in Line2D.markers:
   3         try:
   4             if len(m) == 1 and m != ' ':
   5                 markers.append(m)
   6         except TypeError:
   7             pass

Changing backends

from http://matplotlib.sourceforge.net/backends.html

# the GUI backends
> python subplot_demo.py -dGTK      # GTK GUI with gdk drawing
> python subplot_demo.py -dGTKAgg   # GTK GUI with antigrain rendering
> python subplot_demo.py -dGTKCairo # GTK GUI with Cairo rendering
> python subplot_demo.py -dTkAgg    # Tkinter GUI with antigrain rendering
> python subplot_demo.py -dWX       # WX backend
> python subplot_demo.py -dWXAgg    # WX GUI with antigrain rendering

# The image backends, no window pops up; you must call savefig
> python subplot_demo.py -dAgg     # antigrain geometry backend image
> python subplot_demo.py -dCairo   # Cairo backend
> python subplot_demo.py -dPS      # postscript backend
> python subplot_demo.py -dPDF     # pdf backend
> python subplot_demo.py -dSVG     # SVG backend

iPython

Usage:

note: -d (debug) and -p (profile)

General Python

Software Carpentry

Here are some books to read:

Not really python tips

To make a movie from a bunch of pngs, do

mencoder mf://frame001.jpg,frame002.jpg -mf w=800:h=600:fps=25:type=jpg \
    -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o output.avi

source: mencoder docs

PyNotes (last edited 2010-04-20 18:57:45 by JsOishi)