Python string format examples
Thursday, November 3rd, 2011 Posted in Python, Scientific computing, Software development | No Comments »The format method for Python strings (introduced in 2.6) is very flexible and powerful. It's also easy to use, but the documentation is not very clear. It all makes sense with a few examples. I'll start with one and add ...
How to build ScipPy with Python 2.7.2 on CentOS5
Thursday, August 25th, 2011 Posted in Linux, Python, Scientific computing | 1 Comment »EDIT: added --enable-shared to configure script for building Python, and added /home/yourname/lib to shared library path. This is necessary for building some packages such as pycairo (which you may need to build pygtk and matplotlib). EDIT 2: you should use the ...
Removing an axis or both axes from a matplotlib plot
Wednesday, August 17th, 2011 Posted in Python, Scientific computing | 1 Comment »Sometimes, the frame around a matplotlib plot can detract from the information you are trying to convey. How do you remove the frame, ticks, or axes from a matplotlib plot? [caption id="attachment_632" align="aligncenter" width="300" caption="matplotlib plot without a y axis"][/caption] The full ...
Python: lists to tuples and tuples to lists
Saturday, July 2nd, 2011 Posted in Python | No Comments »Get the code for this example The zip function in Python accepts a number of sequences (such as lists or arrays) and returns a list of tuples. The first element of each tuple comes from the first sequence, the second from ...
A self-contained Fortran linear equation solver
Wednesday, March 16th, 2011 Posted in Fortran, Python, Scientific computing, Software development | No Comments »I've just released a self-contained Fortran module that solves a system of linear equations using the LU decomposition. Download the Fortran linear solver from github This module is based on code that was implemented and released on the Web by Jean-Pierre Moreau. ...
Sage: open-source mathematical software
Monday, March 7th, 2011 Posted in Python, Sage, Scientific computing, Software development | No Comments »I've recently gained a lot of experience with Sage, an open-source alternative to MATLAB, Mathematica, Maple, MuPAD, and Magma. Here are a couple of links to check out: Public notebook servers--try it online right now! Interactive examples with Sage Mathematical publications citing Sage
Linear system simulation with Python
Friday, December 17th, 2010 Posted in Python, Scientific computing, Software development | 2 Comments »Linear time-invariant (LTI) system are widely used in the field of signal processing. Scipy contains powerful tools for simulating LTI systems in the scipy.signal package, but they are not well documented. I will provide a simple example that demonstrates how ...
Constrained least-squares fitting with Python
Friday, March 5th, 2010 Posted in Python, Scientific computing | 1 Comment »Scipy contains a good least-squares fitting routine, leastsq(), which implements a modified Levenberg-Marquardt algorithm. I just learned that it also has a constrained least-squared routine called fmin_slsqp(). I am using simple upper and lower bound constraints, but it's also possible ...
Storing large Numpy arrays on disk: Python Pickle vs. HDF5
Sunday, January 10th, 2010 Posted in Python, Scientific computing, Software development | 1 Comment »In a previous post, I described how Python's Pickle module is fast and convenient for storing all sorts of data on disk. More recently, I showed how to profile the memory usage of Python code. In recent weeks, I've uncovered ...
f2py: binding Fortran and Python
Wednesday, September 23rd, 2009 Posted in Fortran, Python, Software development | No Comments »I have recently started using f2py to call Fortran from Python. I have found this useful for two reasons: speeding up Python scripts by calling compiled Fortran code, and using Python as a unit testing framework for Fortran modules. Unfortunately, ...