def mintegrate(m, var, l1, l2, mname, sufix, norm=False, do_simplify=False,
               conds='none'):
    print('\tstarting integration of {mname} over {var}'.format(
            mname=mname, var=var))
    m = Matrix(m)
    sympy.var('AAA')
    if norm:
        # changing variables
        subs = {var: (l1-l2)*AAA + l1}
        m = m.subs(subs)
        m *= (l2-l1)
    # integration
    for (i, j), ki in np.ndenumerate(m):
        tmp = '{mname}_{sufix}[{i}, {j}] over {var}'.format(mname=mname,
                  sufix=sufix, i=i, j=j, var=var)
        try:
            if norm:
                ki = integrate(ki, (AAA, 0, 1), conds=conds)
            else:
                ki = integrate(ki, (var, l1, l2), conds=conds)
            print('\tfinished integrate {tmp}'.format(tmp=tmp))
        except:
            print('\t\tintegrate() failed for {tmp}'.format(tmp=tmp))
        m[i, j] = ki
    for (i, j), ki in np.ndenumerate(m):
        tmp = '{mname}_{sufix}[{i}, {j}] over {var}'.format(mname=mname,
                  sufix=sufix, i=i, j=j, var=var)
        try:
            if do_simplify:
                ki = simplify(ki)
            else:
                ki = trigsimp(ki)
        except:
            print('\t\ttrigsimp failed {tmp}'.format(tmp=tmp))
            ki = simplify(ki)
        print('\tfinished simplify {tmp}'.format(tmp=tmp))
        m[i, j] = ki
    # printing
    filename = 'print_{mname}_{sufix}_over_{var}.txt'.format(mname=mname,
                   sufix=sufix, var=var)
    with open(filename, 'w') as f:
        def myprint(sth):
            lines.append(str(sth).strip() + '\n')
        myprint('matrix ' + mname + ' in file ' + filename)
        for (i, j), v in np.ndenumerate(m):
            if v:
                myprint(mname + '[{0},{1}] = {2}'.format(i,j,v))
    return m
dataset/ETHPy150Open saullocastro/mapy/mapy/sympytools/matrixtools.py/mintegrate/swapped operands of `-`