# -*- coding: utf-8 -*- """ Created on Thu Aug 30 16:31:10 2018 @author: kaaret """ # make Python 2.7 act like Python 3 from __future__ import division, print_function input = raw_input # import commonly used libraries import numpy as np import matplotlib.pyplot as plt def row_swap(m, i, j) : """ Swap rows i and j of a matrix m. """ mp = m.copy() # make a copy of the input matrix t = mp[i,:].copy() # copy row i of mp, need to copy since next line changes mp mp[i,:] = mp[j,:] # copy row j of mp into row i mp[j,:] = t # put the copy of the original row i into row j return mp def scalar_mult(m, i, c) : """ Multiply row i of matrix m by c. """ mp = m.copy() # make a copy of the input matrix mp[i,:] = c*mp[i,:] # multiply row i by c and put it back into row i return mp def row_add(m, i, j, c) : """ Multiply row i of matrix m by c, add to row j, and replace row j. """ mp = m.copy() # make a copy of the input matrix mp[j,:] = c*mp[i,:]+mp[j,:] # multiply row i by c, add to row j, and put sum back into row j return mp