scripts/primes_scratch.py
def pixel_connectivity(is_prime_square, x_square):
    """
    Count the number of pixels adjacent to each labelled pixel, split into two types of connectivity:
    diagonally and 4-neighbourhood (laterally).
    :param is_prime_square:
    :param x_square:
    :return:
    * pandas.DataFrame
    """

    def is_neigh(is_prime_square, i, j):
        nrow = is_prime_square.shape[0]
        ncol = is_prime_square.shape[1]
        if i < 0 or j < 0 or i >= nrow or j >= ncol:
            return 0
        else:
            return int(is_prime_square[i, j])

    # init outputs
    out_num = []
    out_neigh_d = []
    out_neigh_4 = []

    # loop pixels that correspond to prime numbers
    row, col = np.where(is_prime_square)
    for i, j in zip(row, col):

        # check how many neighbours this pixels is connected to diagonally
        neigh_d = is_neigh(is_prime_square, i - 1, j - 1) \
                  + is_neigh(is_prime_square, i - 1, j + 1) \
                  + is_neigh(is_prime_square, i + 1, j - 1) \
                  + is_neigh(is_prime_square, i + 1, j + 1)

        # check how many neighbours this pixels is connected to laterally
        neigh_4 = is_neigh(is_prime_square, i - 1, j) \
                  + is_neigh(is_prime_square, i + 1, j) \
                  + is_neigh(is_prime_square, i, j - 1) \
                  + is_neigh(is_prime_square, i, j + 1)

        out_num.append(x_square[i, j])
        out_neigh_d.append(neigh_d)
        out_neigh_4.append(neigh_4)

    # put outputs into structured array
    df = pd.DataFrame(data={'num': out_num, 'neigh_d': out_neigh_d, 'neigh_4': out_neigh_4})

    return df

    Count the number of pixels adjacent to each labelled pixel, split into two types of connectivity:
    diagonally and 4-neighbourhood (laterally).
    :param is_prime_square:
    :param x_square:
    :return:
    * pandas.DataFrame
    
Count the number of pixels adjacent to each labelled pixel, split into two types of connectivity:
diagonally and 4-neighbourhood (laterally).
Count the number of pixels adjacent to each labelled pixel split into two types of connectivity : diagonally and 4 - neighbourhood ( laterally ) .
def pixel_connectivity(is_prime_square, x_square):
    def is_neigh(is_prime_square, i, j):
        nrow = is_prime_square.shape[0]
        ncol = is_prime_square.shape[1]
        if i < 0 or j < 0 or i >= nrow or j >= ncol:
            return 0
        else:
            return int(is_prime_square[i, j])
    out_num = []
    out_neigh_d = []
    out_neigh_4 = []
    row, col = np.where(is_prime_square)
    for i, j in zip(row, col):
        neigh_d = is_neigh(is_prime_square, i - 1, j - 1) \
                  + is_neigh(is_prime_square, i - 1, j + 1) \
                  + is_neigh(is_prime_square, i + 1, j - 1) \
                  + is_neigh(is_prime_square, i + 1, j + 1)
        neigh_4 = is_neigh(is_prime_square, i - 1, j) \
                  + is_neigh(is_prime_square, i + 1, j) \
                  + is_neigh(is_prime_square, i, j - 1) \
                  + is_neigh(is_prime_square, i, j + 1)
        out_num.append(x_square[i, j])
        out_neigh_d.append(neigh_d)
        out_neigh_4.append(neigh_4)
    df = pd.DataFrame(data={'num': out_num, 'neigh_d': out_neigh_d, 'neigh_4': out_neigh_4})
    return df
def pixel_connectivity ( is_prime_square , x_square ) : def is_neigh ( is_prime_square , i , j ) : nrow = is_prime_square . shape [ 0 ] ncol = is_prime_square . shape [ 1 ] if i < 0 or j < 0 or i >= nrow or j >= ncol : return 0 else : return int ( is_prime_square [ i , j ] ) out_num = [ ] out_neigh_d = [ ] out_neigh_4 = [ ] row , col = np . where ( is_prime_square ) for i , j in zip ( row , col ) : neigh_d = is_neigh ( is_prime_square , i - 1 , j - 1 ) + is_neigh ( is_prime_square , i - 1 , j + 1 ) + is_neigh ( is_prime_square , i + 1 , j - 1 ) + is_neigh ( is_prime_square , i + 1 , j + 1 ) neigh_4 = is_neigh ( is_prime_square , i - 1 , j ) + is_neigh ( is_prime_square , i + 1 , j ) + is_neigh ( is_prime_square , i , j - 1 ) + is_neigh ( is_prime_square , i , j + 1 ) out_num . append ( x_square [ i , j ] ) out_neigh_d . append ( neigh_d ) out_neigh_4 . append ( neigh_4 ) df = pd . DataFrame ( data = { 'num' : out_num , 'neigh_d' : out_neigh_d , 'neigh_4' : out_neigh_4 } ) return df
Count the number of pixels adjacent to each labelled pixel, split into two types of connectivity:
diagonally and 4-neighbourhood (laterally).
Count the number of pixels adjacent to each labelled pixel split into two types of connectivity : diagonally and 4 - neighbourhood ( laterally ) .
"""
    Count the number of pixels adjacent to each labelled pixel, split into two types of connectivity:
    diagonally and 4-neighbourhood (laterally).
    :param is_prime_square:
    :param x_square:
    :return:
    * pandas.DataFrame
    """ # init outputs # loop pixels that correspond to prime numbers # check how many neighbours this pixels is connected to diagonally # check how many neighbours this pixels is connected to laterally # put outputs into structured array
None
is_prime_square
None
x_square
None