Sunday, 31 August 2014

Useful Numerical Journals

There are various journals which may be of interest to the programmer experimenting with mathematics. Some noteworthy ones include:

Acta Numerica - "survey papers by leading researchers in numerical analysis and scientific computing". It is edited by Cambridge-based computational mathematician, Arieh Iserles.

SIAM Journal on Numerical Analysis - research on development and analysis of numerical methods

Numerische Mathematik - established in 1959

BIT Numerical Mathematics

Sunday, 17 August 2014

Generators in Python

Generators in Python were proposed in PEP 255 and integrated into the language via the yield keyword. Used in conjunction with the while loop, generators can be used create function objects yielding infinite sequences.

Neil Schemenauer is one of the co-authors of the PEP (2 to the power 8, minus 1).

Saturday, 16 August 2014

Function Decorators in Python

They can be used to add "attributes" to a Python function. They look like this:

@specialPowers
def myFunction():
    doStuff

Thinking in Java author Bruce Eckel has written an article on Artima on this.

Writing a Recursive Function in Python

Writing a recursive function in Python is the same as writing a recursive function in any language including functional languages. You have to get your base case and recursive case in order.

Wednesday, 24 July 2013

threading, thread and _thread

thread is the "old school" module for threading, threading is the "new way". _thread is the implementation of threading in Python 3.0.  It was so-named in Py3K to label it as an implementation "detail".

using time module with thread module

import thread; thread.start_new_thread( my_function, (args in a tuple structure).

Then inside my_function,time.sleep(x) to call the grist of the function at regular intervals from within a loop (e..g while true; or while count < x:).

Threads are sometimes called light-weight processes. They do not require as much memory overhead as a regular process.

time in python

If you are creating multi-threaded programs in Python (and, let's face it, who isn't) you need a familiarity with the time module. The time module is always there, but some functions may only work on certain platforms.

time.time() - is the basic thing you need to know. It returns the number of seconds since the "epoch". The epoch is when time starts. On Jan 1 of that year at time 0, the "time since epoch" is zero. On Unix, and in chances are if you try this on Windows too, the epoch is 1970.

time.gmtime(0) - returns the epoch.

time.ctime(xx) - converts a time since the epoch into local time. This will show day, month year and time when printed.

time.sleep(s) - suspends execution for a given number of seconds.