| |
- add(a, b)
- argmax(lst, key=<function <lambda>>)
- Find the index 'i' in 'lst' with maximum lst[i]
lst -- list to search
key -- function to apply to each lst[i].
argmax(lst, key=func) --> argmax(map(key, lst))
- argmin(lst, key=<function <lambda>>)
- Find the index 'i' in 'lst' with minimum lst[i]
lst -- list to search
key -- function to apply to each lst[i].
argmin(lst, key=func) --> argmin(map(key, lst))
- bucket(array, ndivs=None, low=None, width=None, key=<function <lambda>>)
- Group elements of 'array' into 'ndivs' lists
- bucketBin(item, ndivs, low, width)
- Return the bin for an item
- bucketSize(array, ndivs=None, low=None, width=None)
- Determine the bucket size needed to divide the values in array into
'ndivs' evenly sized buckets
- cget(mat, *i)
- Returns the column(s) '*i' of a 2D list 'mat'
mat -- matrix or 2D list
*i -- columns to extract from matrix
notes:
If one column is given, the column is returned as a list.
If multiple columns are given, a list of columns (also lists) is returned
- clamp(x, low, high)
- Clamps a value 'x' between the values 'low' and 'high'
If low == None, then there is no lower bound
If high == None, then there is no upper bound
- clampfunc(low, high)
- compose(*funcs)
- Composes two or more functions into one function
example:
compose(f,g,h,i)(x) <==> f(g(h(i(x))))
- compose2(f, g)
- Compose two functions into one
compose2(f, g)(x) <==> f(g(x))
- concat(*lists)
- Concatenates several lists into one
- count(func, lst)
- Counts the number of times func(x) is True for x in list 'lst'
See also:
counteq(a, lst) count items equal to a
countneq(a, lst) count items not equal to a
countle(a, lst) count items less than or equal to a
countlt(a, lst) count items less than a
countge(a, lst) count items greater than or equal to a
countgt(a, lst) count items greater than a
- counteq(a, lst)
- countge(a, lst)
- countgt(a, lst)
- countle(a, lst)
- countlt(a, lst)
- countneq(a, lst)
- cumsum(vals)
- Returns a cumalative sum of vals (as a list)
- defaultFormat = default_format(val)
- defaultJustify = default_justify(val)
- default_format(val)
- default_justify(val)
- deldir(path)
- Recursively remove a directory
- distrib(array, ndivs=None, low=None, width=None)
- Find the distribution of 'array' using 'ndivs' buckets
- div(a, b)
- eqfunc(a)
- equal(*vals)
- Returns True if all arguments are equal
- evalstr(text)
- Replace expressions in a string (aka string interpolation)
ex:
>>> name = 'Matt'
>>> evalstr("My name is ${name} and my age is ${12+12}")
'My name is Matt and my age is 24'
"${!expr}" expands to "${expr}"
- exceptDefault(func, val, exc=<class exceptions.Exception>)
- Specify a default value for when an exception occurs
- find(func, *lsts)
- Returns the indices 'i' of 'lst' where func(lst[i]) == True
if N lists are passed, N arguments are passed to 'func' at a time.
Thus, find(func, list1, list2) returns the list of indices 'i' where
func(list1[i], list2[i]) == True
See also:
findeq(a, lst) find items equal to a
findneq(a, lst) find items not equal to a
findle(a, lst) find items less than or equal to a
findlt(a, lst) find items less than a
findge(a, lst) find items greater than or equal to a
findgt(a, lst) find items greater than a
- findeq(a, lst)
- findge(a, lst)
- findgt(a, lst)
- findle(a, lst)
- findlt(a, lst)
- findneq(a, lst)
- flatten(lst, depth=inf)
- Flattens nested lists/tuples into one list
depth -- specifies how deep flattening should occur
- frange(start, end, step)
- Generates a range of floats
start -- begining of range
end -- end of range
step -- step size
- gefunc(a)
- groupby(func, lst, multi=False)
- Places i and j of 'lst' into the same group if func(i) == func(j).
func -- is a function of one argument that maps items to group objects
lst -- is a list of items
multi -- if True, func must return a list of keys (key1, ..., keyn) for
item a. groupby will retrun a nested dict 'dct' such that
dct[key1]...[keyn] == a
returns:
a dictionary such that the keys are groups and values are items found in
that group
- gtfunc(a)
- hist(array, ndivs=None, low=None, width=None)
- Create a histogram of 'array' with 'ndivs' buckets
- hist2(array1, array2, ndivs1=None, ndivs2=None, low1=None, low2=None, width1=None, width2=None)
- Perform a 2D histogram
- histDict = hist_dict(array)
- Returns a histogram of any items as a dict.
The keys of the returned dict are elements of 'array' and the values
are the counts of each element in 'array'.
- histInt = hist_int(array)
- Returns a histogram of integers as a list of counts
- hist_dict(array)
- Returns a histogram of any items as a dict.
The keys of the returned dict are elements of 'array' and the values
are the counts of each element in 'array'.
- hist_int(array)
- Returns a histogram of integers as a list of counts
- histbins(bins)
- Adjust the bins from starts to centers, this will allow GNUPLOT to plot
histograms correctly
- icumsum(vals)
- Returns a cumalative sum of vals (as an iterator)
- idiv(a, b)
- int2pretty(num)
- Returns a pretty-printed version of an int
- invPerm = invperm(perm)
- Returns the inverse of a permutation 'perm'
- invcmp(a, b)
- invperm(perm)
- Returns the inverse of a permutation 'perm'
- islands(lst)
- Takes a iterable and returns islands of equal consequtive items
Return value is a dict with the following format
counts = {elm1: [(start,end), (start,end), ...],
elm2: [(start,end), (start,end), ...]
...}
where for each (start,end) in counts[elm1] we have lst[start:end] only
containing elm1
- lefunc(a)
- lg(num)
- Retruns the log_2 of a number
- list2lookup(lst)
- Creates a dict where each key is lst[i] and value is i
- list2matrix(lst, nrows=None, ncols=None, bycols=True)
- Turn a list into a matrix by wrapping its entries
- listFiles = list_files(path, ext='')
- Returns a list of files in 'path' ending with 'ext'
- list_files(path, ext='')
- Returns a list of files in 'path' ending with 'ext'
- ltfunc(a)
- makeMatrix = make_matrix(nrows, ncols, val=0)
- make_matrix(nrows, ncols, val=0)
- map2(func, *matrix)
- Maps a function onto the elements of a matrix
Also accepts multiple matrices. Thus matrix addition is
map2(add, matrix1, matrix2)
- mapapply(funcs, lst)
- apply each function in 'funcs' to one element in 'lst'
- mapdict(dic, key=<function <lambda>>, val=<function <lambda>>, keyfunc=None, valfunc=None)
- Creates a new dict where keys and values are mapped
keyfunc and valfunc are DEPRECATED
- mapwindow(func, size, lst)
- Apply a function 'func' to a sliding window of size 'size' within
a list 'lst'
- match(pattern, text)
- A quick way to do pattern matching.
remember: to name tokens use (?P<name>pattern)
- max2(matrix)
- Finds the maximum of a 2D list or matrix
- maxfunc(func, lst)
- Find the element 'e' in 'lst' with maximum func(e)
- mget(lst, ind)
- Returns a list 'lst2' such that lst2[i] = lst[ind[i]]
Or in otherwords, get the subsequence 'lst'
- min2(matrix)
- Finds the minimum of a 2D list or matrix
- minfunc(func, lst)
- Find the element 'e' in 'lst' with minimum func(e)
- mul(a, b)
- neqfunc(a)
- oneNorm(vals)
- Normalize values so that they sum to 1
- openStream = open_stream(filename, mode='r')
- Returns a file stream depending on the type of 'filename' and 'mode'
The following types for 'filename' are handled:
stream - returns 'filename' unchanged
iterator - returns 'filename' unchanged
URL string - opens http pipe
'-' - opens stdin or stdout, depending on 'mode'
other string - opens file with name 'filename'
mode is standard mode for file(): r,w,a,b
- open_stream(filename, mode='r')
- Returns a file stream depending on the type of 'filename' and 'mode'
The following types for 'filename' are handled:
stream - returns 'filename' unchanged
iterator - returns 'filename' unchanged
URL string - opens http pipe
'-' - opens stdin or stdout, depending on 'mode'
other string - opens file with name 'filename'
mode is standard mode for file(): r,w,a,b
- overlap(a, b, x, y, inc=True)
- Returns True if range [a,b] overlaps [x,y]
inc -- if True, treat [a,b] and [x,y] as inclusive
- pretty2int(string)
- Parses a pretty-printed version of an int into an int
- printDict = print_dict(dic, key=<function <lambda>>, val=<function <lambda>>, num=None, cmp=<built-in function cmp>, order=None, reverse=False, spacing=4, out=<open file '<stdout>', mode 'w'>, format=<function default_format>, justify=<function default_justify>)
- Print s a dictionary in two columns
- printHist = print_hist(array, ndivs=20, low=None, width=None, cols=75, spacing=2, out=<open file '<stdout>', mode 'w'>)
- print_dict(dic, key=<function <lambda>>, val=<function <lambda>>, num=None, cmp=<built-in function cmp>, order=None, reverse=False, spacing=4, out=<open file '<stdout>', mode 'w'>, format=<function default_format>, justify=<function default_justify>)
- Print s a dictionary in two columns
- print_hist(array, ndivs=20, low=None, width=None, cols=75, spacing=2, out=<open file '<stdout>', mode 'w'>)
- printcols(data, width=None, spacing=1, format=<function default_format>, justify=<function default_justify>, out=<open file '<stdout>', mode 'w'>, colwidth=inf, overflow='!')
- Prints a list or matrix in aligned columns
data - a list or matrix
width - maxium number of characters per line (default: 75 for lists)
spacing - number of spaces between columns (default: 1)
out - stream to print to (default: sys.stdout)
- printwrap(text, width=80, prefix='', out=<open file '<stdout>', mode 'w'>)
- Prints text with wrapping
- range2(width, height)
- Iterates over the indices of a matrix
Thus list(range2(3, 2)) returns
[(0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (2, 1)]
- readDelim = read_delim(filename, delim=None)
- Read an entire delimited file into memory as a 2D list
- readDict = read_dict(filename, delim='\t', keytype=<type 'str'>, valtype=<type 'str'>)
- Read a dict from a file
filename may also be a stream
- readFloats = read_floats(filename)
- Read a list of floats from a file (one float per line)
filename may also be a stream
- readInts = read_ints(filename)
- Read a list of integers from a file (one int per line)
filename may also be a stream
- readStrings = read_strings(filename)
- Read a list of strings from a file (one string per line)
filename may also be a stream
- readUntil = read_until(stream, chars)
- readWhile = read_while(stream, chars)
- readWord = read_word(infile, delims=[' ', '\t', '\n'])
- read_delim(filename, delim=None)
- Read an entire delimited file into memory as a 2D list
- read_dict(filename, delim='\t', keytype=<type 'str'>, valtype=<type 'str'>)
- Read a dict from a file
filename may also be a stream
- read_floats(filename)
- Read a list of floats from a file (one float per line)
filename may also be a stream
- read_ints(filename)
- Read a list of integers from a file (one int per line)
filename may also be a stream
- read_strings(filename)
- Read a list of strings from a file (one string per line)
filename may also be a stream
- read_until(stream, chars)
- read_while(stream, chars)
- read_word(infile, delims=[' ', '\t', '\n'])
- remove(lst, *vals)
- Returns a copy of list 'lst' with values 'vals' removed
- replaceExt = replace_ext(filename, oldext, newext)
- Safely replaces a file extension new a new one
- replace_ext(filename, oldext, newext)
- Safely replaces a file extension new a new one
- revdict(dic, allowdups=False)
- Reverses a dict 'dic' such that the keys become values and the
values become keys.
allowdups -- if True, one of several key-value pairs with the same value
will be arbitrarily choosen. Otherwise an expection is raised
- reverse(lst)
- Returns a reversed copy of a list
- safediv(a, b, default=inf)
- safelog(x, base=2.7182818284590451, default=-inf)
- sign(num)
- Returns the sign of a number
- skipComments = skip_comments(infile)
- skip_comments(infile)
- sort(lst, compare=<built-in function cmp>, key=None, reverse=False)
- Returns a sorted copy of a list
python2.4 now has sorted() which fulfills the same purpose
lst -- a list to sort
compare -- a function for comparing items (default: cmp)
key -- function of one arg to map items
reverse -- when True reverse sorting
- sortInd = sortrank(lst, cmp=<built-in function cmp>, key=None, reverse=False)
- Returns the ranks of items in lst
- sortTogether = sort_together(compare, lst, *others)
- Sort several lists based on the sorting of 'lst'
- sort_many(lst, *others, **args)
- Sort several lists based on the sorting of 'lst'
- sort_together(compare, lst, *others)
- Sort several lists based on the sorting of 'lst'
- sortrank(lst, cmp=<built-in function cmp>, key=None, reverse=False)
- Returns the ranks of items in lst
- sqrt(...)
- sqrt(x)
Return the square root of x.
- str2bool(val)
- Correctly converts the strings "True" and "False" to the
booleans True and False
- sub(a, b)
- subdict(dic, keys)
- Returns a new dictionary dic2 such that
dic2[i] = dic[i] for all i in keys
dic -- a dictionary
keys -- a list of keys
- submatrix(mat, rows=None, cols=None)
- Returns a submatrix of 'mat' with only the rows and columns specified
Rows and columns will appear in the order as indicated in 'rows' and 'cols'
- tempfile(path, prefix, ext)
- Generates a a temp filename 'path/prefix_XXXXXX.ext'
DEPRECATED: use this instead
fd, filename = temporaryfile.mkstemp(ext, prefix)
os.close(fd)
- transpose(mat)
- Transpose a matrix
Works better than zip() in that rows are lists not tuples
- unique(lst)
- Returns a copy of 'lst' with only unique entries.
The list is stable (the first occurance is kept).
- withinfunc(a, b, ainc=True, binc=True)
- writeDelim = write_delim(filename, data, delim='\t')
- Write a 2D list into a file using a delimiter
- writeDict = write_dict(filename, dct, delim='\t')
- Write a dictionary to a file
- writeList = write_list(filename, lst)
- Write a list of anything (ints, floats, strings, etc) to a file.
filename may also be a stream
- writeVector = write_list(filename, lst)
- Write a list of anything (ints, floats, strings, etc) to a file.
filename may also be a stream
- write_delim(filename, data, delim='\t')
- Write a 2D list into a file using a delimiter
- write_dict(filename, dct, delim='\t')
- Write a dictionary to a file
- write_list(filename, lst)
- Write a list of anything (ints, floats, strings, etc) to a file.
filename may also be a stream
|