def jtosparse(j):
    """
    Generate sparse matrix coordinates from 3-D Jacobian.
    """
    data = j.flatten().tolist()
    nobs, nf, nargs = j.shape
    indices = zip(*[(r, c) for n in xrange(nobs)
                    for r in xrange(n * nf, (n + 1) * nf)
                    for c in xrange(n * nargs, (n + 1) * nargs)])
    return csr_matrix((data, indices), shape=(nobs * nf, nobs * nargs))
def jtosparse ( j ) : data = j . flatten ( ) . tolist ( ) nobs , nf , nargs = j . shape indices = zip ( * [ ( r , c ) for n in xrange ( nobs ) for r in xrange ( n * nf , ( n + 1 ) * nf ) for c in xrange ( n * nargs , ( n + 1 ) * nargs ) ] ) return csr_matrix ( ( data , indices ) , shape = ( nobs * nf , nobs * nargs ) )
Generate sparse matrix coordinates from 3-D Jacobian.