(shape, sample_size, seeds, grid=13, seed=1, flat=False)
return sampind
Returns a (end-start) sets of sample_size grid points within
    the shape given.  If the shape dimensions are a multiple of 'grid',
    then sampled points within the same row will never be duplicated.
Returns a (end-start) sets of sample_size grid points within
    the shape given.  If the shape dimensions are a multiple of 'grid',
    then sampled points within the same row will never be duplicated.
Returns a ( end - start ) sets of sample_size grid points within the shape given . If the shape dimensions are a multiple of grid then sampled points within the same row will never be duplicated .
def coordinate_sample(shape, sample_size, seeds, grid=13, seed=1, flat=False):
    '''
    Returns a (end-start) sets of sample_size grid points within
    the shape given.  If the shape dimensions are a multiple of 'grid',
    then sampled points within the same row will never be duplicated.
    '''
    if flat:
        sampind = numpy.zeros((len(seeds), sample_size), dtype=int)
    else:
        sampind = numpy.zeros((len(seeds), 2, sample_size), dtype=int)
    assert sample_size <= grid
    for j, seed in enumerate(seeds):
        rng = numpy.random.RandomState(seed)
        # Shuffle the 169 random grid squares, and pick :sample_size.
        square_count = grid ** len(shape)
        square = numpy.stack(numpy.unravel_index(
            rng.choice(square_count, square_count)[:sample_size],
            (grid,) * len(shape)))
        # Then add a random offset to each x, y and put in the range [0...1)
        # Notice this selects the same locations regardless of resolution.
        uniform = (square + rng.uniform(size=square.shape)) / grid
        # TODO: support affine scaling so that we can align receptive field
        # centers exactly when sampling neurons in different layers.
        coords = (uniform * numpy.array(shape)[:,None]).astype(int)
        # Now take sample_size without replacement.  We do this in a way
        # such that if sample_size is decreased or increased up to 'grid',
        # the selected points become a subset, not totally different points.
        if flat:
            sampind[j] = numpy.ravel_multi_index(coords, dims=shape)
        else:
            sampind[j] = coords
    return sampind
def coordinate_sample ( shape , sample_size , seeds , grid = 13 , seed = 1 , flat = False ) : if flat : sampind = numpy . zeros ( ( len ( seeds ) , sample_size ) , dtype = int ) else : sampind = numpy . zeros ( ( len ( seeds ) , 2 , sample_size ) , dtype = int ) assert sample_size <= grid for j , seed in enumerate ( seeds ) : rng = numpy . random . RandomState ( seed ) # Shuffle the 169 random grid squares, and pick :sample_size. square_count = grid ** len ( shape ) square = numpy . stack ( numpy . unravel_index ( rng . choice ( square_count , square_count ) [ : sample_size ] , ( grid , ) * len ( shape ) ) ) # Then add a random offset to each x, y and put in the range [0...1) # Notice this selects the same locations regardless of resolution. uniform = ( square + rng . uniform ( size = square . shape ) ) / grid # TODO: support affine scaling so that we can align receptive field # centers exactly when sampling neurons in different layers. coords = ( uniform * numpy . array ( shape ) [ : , None ] ) . astype ( int ) # Now take sample_size without replacement.  We do this in a way # such that if sample_size is decreased or increased up to 'grid', # the selected points become a subset, not totally different points. if flat : sampind [ j ] = numpy . ravel_multi_index ( coords , dims = shape ) else : sampind [ j ] = coords return sampind