<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def writetoPAJ(CIJ, fname, directed):
    '''
    This function writes a Pajek .net file from a numpy matrix

    Parameters
    ----------
    CIJ : NxN np.ndarray
        adjacency matrix
    fname : str
        filename
    directed : bool
        True if the network is directed and False otherwise. The data format
        may be required to know this for some reason so I am afraid to just
        use directed as the default value.
    '''
    n = np.size(CIJ, axis=0)
    with open(fname, 'w') as fd:
        fd.write('*vertices %i \r' % n)
        for i in range(1, n + 1):
            fd.write('%i "%i" \r' % (i, i))
        if directed:
            fd.write('*arcs \r')
        else:
            fd.write('*edges \r')
        for i in range(n):
            for j in range(n):
                if CIJ[i, j] != 0:
                    fd.write('%i %i %.6f \r' % (i + 1, j + 1, CIJ[i, j]))