'''Library of simple helpful functions and definitions for CS515 class.''' import sys # a cheap form of the numpy zeros routine def zeros(x, y, value=0.0) : l = [] for i in range(0, x) : l.append(y * [value]) return l # print out a matrix def printMatrix(mat, symbol=None) : for line in mat : for item in line : if symbol==None : print("%5s "%item, end="") else : print("%5s "%symbol[item], end="") print() # returns tuple (location of maximum, maximum value) # where location of maximum is the location of the FIRST maximum # Assumes list is nonempty. def argmax(s): max = s[0]; maxa = 0; for i in range(1, len(s)) : if s[i]>max: max = s[i] maxa = i return (maxa, max) # returns tuple (tuple of location of maximum, maximum value) # where location of maximum is the location of the FIRST maximum # mat has to be 2D and nonempty but does not have to be rectanglar # return coordinates of max and maximum def argmax2D(mat) : maxr = 0 maxc = 0 max = mat[maxr][maxc] r = 0 for row in mat : c = 0 for item in row : if mat[r][c]>max : max = mat[r][c] maxr = r maxc = c c+=1 r+=1 return ((maxr, maxc), max) def readStr() : return sys.stdin.readline().rstrip() def readNum() : return float(sys.stdin.readline().rstrip()) def readListStr() : return sys.stdin.readline().rstrip().split() def readListNum() : return [float(x) for x in sys.stdin.readline().rstrip().split()]