def to_pattern_matrix(D):
result = np.zeros_like(D)<EOL>result[D.nonzero()] = <NUM_LIT:1><EOL>return result<EOL>
Returns the Boolean matrix in the same shape as `D` with ones exactly
    where there are nonzero entries in `D`.

    `D` must be a NumPy array.