scripts/primes_scratch.py
def prop_primes(x):
    """
    Compute proportion of prime numbers in each row/column (even length squares) or diagonal/antidiagonal (odd length
    squares).

    :param x:
    :return:
    """

    # length of square length
    n = x.shape[0]

    if n % 2 == 1:  # odd length square

        prop_fw = []
        for k in range(n - 1, -n, -1):
            diag = np.diagonal(x, k)
            prop_fw.append(np.count_nonzero(diag) / len(diag))

        x = np.fliplr(x)
        prop_bk = []
        for k in range(n - 1, -n, -1):
            diag = np.diagonal(x, k)
            prop_bk.append(np.count_nonzero(diag) / len(diag))

    else:  # even length square

        prop_fw = np.sum(x, axis=1) / n  # rows
        prop_bk = np.sum(x, axis=0) / n  # columns

    if DEBUG:
        if n % 2 == 1:  # odd length square

            plt.clf()
            (markers, stemlines, baseline) = plt.stem(range(n - 1, -n, -1), prop_fw, label='Diagonals')
            plt.setp(markers, marker='D', markersize=6, markeredgecolor="C0", markeredgewidth=2)
            plt.stem(range(n - 1, -n, -1), prop_bk, linefmt='C1', markerfmt='C1o', label='Antidiagonals')
            plt.xlabel('Diagonal index')
            plt.ylabel('Primes proportion')
            plt.legend()

        else:

            plt.clf()
            (markers, stemlines, baseline) = plt.stem(prop_fw, label='Rows')
            plt.setp(markers, marker='D', markersize=6, markeredgecolor="C0", markeredgewidth=2)
            plt.stem(prop_bk, linefmt='C1', markerfmt='C1o', label='Columns')
            plt.xlabel('Row/column index')
            plt.ylabel('Primes proportion')
            plt.legend()

    return np.array(prop_fw), np.array(prop_bk)

    Compute proportion of prime numbers in each row/column (even length squares) or diagonal/antidiagonal (odd length
    squares).

    :param x:
    :return:
    
Compute proportion of prime numbers in each row/column (even length squares) or diagonal/antidiagonal (odd length
squares).
Compute proportion of prime numbers in each row / column ( even length squares ) or diagonal / antidiagonal ( odd length squares ) .
def prop_primes(x):
    n = x.shape[0]
    if n % 2 == 1:  
        prop_fw = []
        for k in range(n - 1, -n, -1):
            diag = np.diagonal(x, k)
            prop_fw.append(np.count_nonzero(diag) / len(diag))
        x = np.fliplr(x)
        prop_bk = []
        for k in range(n - 1, -n, -1):
            diag = np.diagonal(x, k)
            prop_bk.append(np.count_nonzero(diag) / len(diag))
    else:  
        prop_fw = np.sum(x, axis=1) / n  
        prop_bk = np.sum(x, axis=0) / n  
    if DEBUG:
        if n % 2 == 1:  
            plt.clf()
            (markers, stemlines, baseline) = plt.stem(range(n - 1, -n, -1), prop_fw, label='Diagonals')
            plt.setp(markers, marker='D', markersize=6, markeredgecolor="C0", markeredgewidth=2)
            plt.stem(range(n - 1, -n, -1), prop_bk, linefmt='C1', markerfmt='C1o', label='Antidiagonals')
            plt.xlabel('Diagonal index')
            plt.ylabel('Primes proportion')
            plt.legend()
        else:
            plt.clf()
            (markers, stemlines, baseline) = plt.stem(prop_fw, label='Rows')
            plt.setp(markers, marker='D', markersize=6, markeredgecolor="C0", markeredgewidth=2)
            plt.stem(prop_bk, linefmt='C1', markerfmt='C1o', label='Columns')
            plt.xlabel('Row/column index')
            plt.ylabel('Primes proportion')
            plt.legend()
    return np.array(prop_fw), np.array(prop_bk)
def prop_primes ( x ) : n = x . shape [ 0 ] if n % 2 == 1 : prop_fw = [ ] for k in range ( n - 1 , - n , - 1 ) : diag = np . diagonal ( x , k ) prop_fw . append ( np . count_nonzero ( diag ) / len ( diag ) ) x = np . fliplr ( x ) prop_bk = [ ] for k in range ( n - 1 , - n , - 1 ) : diag = np . diagonal ( x , k ) prop_bk . append ( np . count_nonzero ( diag ) / len ( diag ) ) else : prop_fw = np . sum ( x , axis = 1 ) / n prop_bk = np . sum ( x , axis = 0 ) / n if DEBUG : if n % 2 == 1 : plt . clf ( ) ( markers , stemlines , baseline ) = plt . stem ( range ( n - 1 , - n , - 1 ) , prop_fw , label = 'Diagonals' ) plt . setp ( markers , marker = 'D' , markersize = 6 , markeredgecolor = "C0" , markeredgewidth = 2 ) plt . stem ( range ( n - 1 , - n , - 1 ) , prop_bk , linefmt = 'C1' , markerfmt = 'C1o' , label = 'Antidiagonals' ) plt . xlabel ( 'Diagonal index' ) plt . ylabel ( 'Primes proportion' ) plt . legend ( ) else : plt . clf ( ) ( markers , stemlines , baseline ) = plt . stem ( prop_fw , label = 'Rows' ) plt . setp ( markers , marker = 'D' , markersize = 6 , markeredgecolor = "C0" , markeredgewidth = 2 ) plt . stem ( prop_bk , linefmt = 'C1' , markerfmt = 'C1o' , label = 'Columns' ) plt . xlabel ( 'Row/column index' ) plt . ylabel ( 'Primes proportion' ) plt . legend ( ) return np . array ( prop_fw ) , np . array ( prop_bk )
Compute proportion of prime numbers in each row/column (even length squares) or diagonal/antidiagonal (odd length
squares).
Compute proportion of prime numbers in each row / column ( even length squares ) or diagonal / antidiagonal ( odd length squares ) .
"""
    Compute proportion of prime numbers in each row/column (even length squares) or diagonal/antidiagonal (odd length
    squares).

    :param x:
    :return:
    """ # length of square length # odd length square # even length square # rows # columns # odd length square
None
x
None