本文整理汇总了Python中matrix.Matrix.setrowVals方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.setrowVals方法的具体用法?Python Matrix.setrowVals怎么用?Python Matrix.setrowVals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.setrowVals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: minpath
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import setrowVals [as 别名]
def minpath(nrows) :
mat = Matrix(1,2)
tri = Matrix(nrows,nrows)
org = Matrix(nrows,nrows)
for r in range(nrows) :
vals = [randint(1,9) for c in range(r+1)]
tri.setrowVals(r,vals)
org.setrowVals(r,vals)
org.title = "Original Values"
mat[0,0] = renderTriangle(org)
mat.tableAttr='border="1" cellspacing="0" cellpadding="4"'
tri.style.setrowVal(nrows-1,"background-color:lightgreen")
for row in range(nrows-2,-1,-1) :
for col in range(row+1) :
left = tri[row+1,col]
right= tri[row+1,col+1]
this = tri[row,col]
tri.style[row,col] = "background-color:pink"
tri.title = "Set to min(%s+%s, %s+%s)" % (this,left,this,right)
mat[0,1] = renderTriangle(tri)
htmlPage.item1 = mat.renderHtml()
htmlPage.makeFrame() #break
tri[row,col] = best = min(this+left,this+right)
tri.style[row,col] = "background-color:lightgreen"
mat[0,1] = renderTriangle(tri)
htmlPage.item1 = mat.renderHtml()
htmlPage.banner = "Miniumum cost is %s" % best
htmlPage.makeFrame() #break
示例2: HtmlFrame
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import setrowVals [as 别名]
maxwgt = 10
vals = [0,10,40,30,50]
wgts = [0, 5, 4, 6, 3]
htmlPage = HtmlFrame()
htmlPage.banner = "Knapsack Problem"
headers=['wt'+str(i) for i in range(maxwgt+1)]
inp = Matrix(len(vals),3)
inp.title = "Sack holds weight %s" % maxwgt
inp.dftFormat = "<pre>%03s</pre>"
inp.tableAttr = 'border="1" cellspacing="0" cellpadding="4"',
inp.tableHeaders=['Item #','Weight','Value']
for i in range(len(vals)) :
inp.setrowVals(i, [i, wgts[i], vals[i]])
frame = Matrix(1,2)
frame[0,0] = inp.renderHtml()
nItems = len(vals)
best = Matrix(nItems,maxwgt+1)
best.dftFormat = "<pre>%03s</pre>"
for i in range(1,nItems) :
best.setrowVal(i,0)
for i in range(1,nItems) :
for w in range(0,maxwgt+1) :
remBest = best[i-1,w-wgts[i]]
if remBest == None : remBest = 0
newSolution = vals[i]+remBest
if ((wgts[i] <= w and newSolution > best[i-1,w])) :