Archive for the ‘Code’ Category

Creating functions dynamically

Sometimes you want to create functions on the fly, at runtime. This came up when using some of the SciPy optimisation functions that require constraints on the variables to be defined as functions.

(more…)

Bitwise operators in Python

Python has logical operators (like ‘and’) and bitwise operators (like ‘&’). Bitwise operators are not that common in Python code, but they can be extremely useful in some cases. For example, in RhinoPython they are used to work with geometry type filters.

(more…)

Computational Geometry in Python

This post provides a list of Python functions that are very common in structural design calculations. They are not specifically optimised in any way. Therefore, you may end up using entirely different implementations in a real project. The list is a work in progress. I will try to add more examples soon…

(more…)

Running Matlab as a Python subprocess

Although NumPy and Scipy usually provide all the tools you need (and more) for scientific computing, sometimes you may want to use a bit of Matlab in the background. In my case, for example, to use rref. Conveniently, Matlab can be run as a Python subprocess, provided of course that Matlab is installed on your system.

(more…)

Adding methods to Python classes

The normal way to add functionality (methods) to a class in Python is to define functions in the class body. There are many other ways to accomplish this that can be useful in different situations.

(more…)

Working with Sublime

Sublime Text is great, but using it properly is not as transparent as what most of us are used to. I will try to list here some of the things i had to figure out to start working efficiently.

(more…)

TeXlipse and Biblatex

Biblatex is a package for LateX that provides more control over the way references are managed. A quick introduction can be found here, and more detailed information here. Using the package with all the default values works great, but then you are not really making the most of it. Once you start changing options, there is one important thing you should know…

(more…)