@@ -0,0 +1,2758 @@
+%22%22%22====================================================%0A                    DESCRIPTION%0A%0A=======================================================%0A%22%22%22%0A__author__ = 'ronny'%0Aimport numpy as np%0A%0A#===============================================================================%0A#                                                      Pairs of All Grid points%0A#===============================================================================%0Adef grid_point_pairs(x_range=(-4,4), y_range=(-4,4), x_step=0.1, y_step=0.1):%0A    %22%22%22%0A    generate all points of a grid within a range of values and step sizes.%0A%0A    :param x_range: tuple of min and max values (inclusive)%0A    :param y_range: tuple of min and max values (inclusive)%0A    :param x_step: step size along x axis%0A    :param y_step: step size along y axis%0A    :return: 2D-Array, with each row being an x,y pair representing a point in%0A             the grid.%0A    %22%22%22%0A    arrays = %5Bnp.arange(x_range%5B0%5D, x_range%5B1%5D + x_step, x_step),%0A              np.arange(y_range%5B0%5D, y_range%5B1%5D + y_step, y_step)%5D%0A    return all_element_combinations(arrays)%0A%0A%0A#===============================================================================%0A#                                                      all_element_combinations%0A#===============================================================================%0Adef all_element_combinations(arrays, out=None):%0A    %22%22%22%0A    code written by: pv.%0A    taken from http://stackoverflow.com/a/1235363%0A%0A    Generate a cartesian product of input arrays.%0A%0A    Parameters%0A    ----------%0A    arrays : list of array-like%0A        1-D arrays to form the cartesian product of.%0A    out : ndarray%0A        Array to place the cartesian product in.%0A%0A    Returns%0A    -------%0A    out : ndarray%0A        2-D array of shape (M, len(arrays)) containing cartesian products%0A        formed of input arrays.%0A%0A    Examples%0A    --------%0A    %3E%3E%3E all_element_combinations((%5B1,2,3%5D, %5B10, 20%5D))%0A    array(%5B%5B 1, 10%5D,%0A           %5B 1, 20%5D,%0A           %5B 2, 10%5D,%0A           %5B 2, 20%5D,%0A           %5B 3, 10%5D,%0A           %5B 3, 20%5D%5D)%0A%0A    %22%22%22%0A    arrays = %5Bnp.asarray(x) for x in arrays%5D%0A    dtype = arrays%5B0%5D.dtype                # to preserve same element datatype%0A    n = np.prod(%5Bx.size for x in arrays%5D)  # Number of combinations%0A%0A    # Initialise the output pairs to zeros%0A    if out is None:%0A        out = np.zeros(%5Bn, len(arrays)%5D, dtype=dtype) # preserves element datatype%0A%0A    m = n / arrays%5B0%5D.size%0A    # populate the values for the very first axis%0A    out%5B:,0%5D = np.repeat(arrays%5B0%5D, m)%0A%0A    # recursively workout the values of the other axes.%0A    if arrays%5B1:%5D:%0A        all_element_combinations(arrays%5B1:%5D, out=out%5B0:m,1:%5D)%0A        for j in xrange(1, arrays%5B0%5D.size):%0A            out%5Bj*m:(j+1)*m,1:%5D = out%5B0:m,1:%5D%0A    return out%0A

Add grid_points