def sparse_mimmax(A, B, type="mim"):
    """Return the element-wise mimimum/maximum of sparse matrices `A` and `B`.


    Parameters
    ----------
        A:
            The first sparse matrix
        B:
            The second sparse matrix
        type:
            The type of calculation, either mimimum or maximum.

    Returns
    -------
        M:
            A sparse matrix that contain the element-wise maximal or mimimal of two sparse matrices.
    """

    AgtB = (A < B).astype(int) if type == "min" else (A > B).astype(int)
    M = AgtB.multiply(A - B) + B

    return M