def merge_explicit(matmul):
    if not any(isinstance(arg, MatrixBase) for arg in matmul.args):
        return matmul
    newargs = []
    last = matmul.args[0]
    for arg in matmul.args[1:]:
        if isinstance(arg, (MatrixBase, Number)) and isinstance(last, (MatrixBase, Number)):
            last = last * arg
        else:
            newargs.append(last)
            last = arg
    newargs.append(last)

    return MatMul(*newargs)
Merge explicit MatrixBase arguments
dataset/ETHPy150Open sympy/sympy/sympy/matrices/expressions/matmul.py/merge_explicit