import sys, string, os, math, re, random, operator, pickle, cPickle, glob, copy, bisect import array, Numeric, LinearAlgebra, RandomArray, numarray, RandomArray2, LinearAlgebra2 #import pstat, stats, io # modest statistics module, had some problems # # Abbreviations of modules: O = operator B = bisect S = string M = math N = Numeric R = RandomArray # comes with Numeric L = LinearAlgebra # dito # The above takes some of the tedium out of qualified references ("module.function"), # and yet it preserves the ability to use "dir()" and "doc()" queries. # # Abbreviations of important matrix operations: N.a = N.array N.m = N.matrixmultiply N.t = N.transpose N.i = N.innerproduct # # Some basic linear algebra functions: N.sqnorm = lambda x: N.i(x,x) N.norm = lambda x: N.sqrt(N.i(x,x)) N.std = lambda x: N.a(x) / N.norm(x) N.center = lambda x: N.a(x) - N.sum(x)/N.size(x) N.cor = lambda x,y: N.i(x,y) / (N.norm(x) * N.norm(y)) N.ang = lambda x,y: N.arccos( N.i(x,y) / (N.norm(x) * N.norm(y)) ) N.ang360 = lambda x,y: N.arccos( N.i(x,y) / (N.norm(x) * N.norm(y)) ) /math.pi * 180. # # Use "doc()" parallel with "dir()": def doc(x): print x.__doc__ # # Create a sorted copy (NOT in place!): works only for lists!!! def sort(x): from copy import copy; y = copy(x); y.sort(); return y