def min_nondiag_triple(matrix):
    """Returns a triple consisting of a row #, col #, and value
    of a minimal non-diagonal entry of matrix."""
    if (not len(matrix) > 1) or (not len(matrix[0]) > 1):
        print("ERROR in min_nondiag_triple: matrix too small")
        return
    minval = matrix[0][1]
    mini = 0
    minj = 1
    for i in range(len(matrix)):
        for j in range(len(matrix[i])):
            if i != j and matrix[i][j] < minval:
                mini, minj, minval = i, j, matrix[i][j]
    return mini, minj, minval