当前位置: 首页>>代码示例>>Python>>正文


Python Matrix.renderHtml方法代码示例

本文整理汇总了Python中matrix.Matrix.renderHtml方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.renderHtml方法的具体用法?Python Matrix.renderHtml怎么用?Python Matrix.renderHtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matrix.Matrix的用法示例。


在下文中一共展示了Matrix.renderHtml方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: minpath

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import renderHtml [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
开发者ID:Chris-Meyers,项目名称:OnlinePythonTutor,代码行数:32,代码来源:optMinpath.py

示例2: HtmlFrame

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import renderHtml [as 别名]
# o p t F i b . p y
#
#  Chris Meyers. 10/26/2013
#
from htmlFrame import HtmlFrame
from matrix    import Matrix

htmlPage = HtmlFrame()
htmlPage.banner = "Animated Fibonacci Sequence"
BOLD   = "color:red;font-weight:bold;"

fibs = Matrix(1,20)
fibs.tableAttr = 'cellspacing="0" cellpadding="10"'
fibs[0,0] = 1
fibs[0,1] = 1

for i in range(2,100) :
    fibs.style[0,i-1] = BOLD
    fibs.style[0,i-2] = BOLD
    fibs[0,i] = fibs[0,i-1]+fibs[0,i-2]
    fibs.title = "Last 2 elements add for new one"
    htmlPage.item1 = fibs.renderHtml(wrap=10)
    htmlPage.makeFrame()    #break
    fibs.style[0,i-2] = ""  # uncolor behind

开发者ID:Chris-Meyers,项目名称:OnlinePythonTutor,代码行数:26,代码来源:optFib.py

示例3: HtmlFrame

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import renderHtml [as 别名]
htmlPage = HtmlFrame()
htmlPage.banner = "Animated Sieve of Erastosthenes"
BOLD   = "color:red;font-weight:bold;"

primes = Matrix(1,20)
primes.tableAttr = 'cellspacing="0" cellpadding="10"'
primes[0,0] = 2
nprimes = 1

for x in range(3,21) :
    primeSofar = True
    for px in range(nprimes) :
        primes.title = "Testing if %s is divisible by primes so far" % x
        primes.style[0,px] = BOLD
        htmlPage.item1 = primes.renderHtml(wrap=5)
        htmlPage.makeFrame()           #break
        primes.style[0,px] = ""
        div = primes[0,px]
        if x % div == 0 : primeSofar = False
        if not primeSofar : break

    if primeSofar :
        primes[0,nprimes] = x
        nprimes += 1
        primes.title = "Found a new prime %s" % x
    else :
        primes.title = "Not Prime: %s mod %s is zero" % (x,div)
    htmlPage.item1 = primes.renderHtml(wrap=5)
    htmlPage.makeFrame()
开发者ID:Chris-Meyers,项目名称:OnlinePythonTutor,代码行数:31,代码来源:optSieve.py

示例4: HtmlFrame

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import renderHtml [as 别名]
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])) :
      best[i,w] = newSolution
      best.style[i,w] = "background-color:pink"
      best.title = "Optimal solution for weight %s includes item %s" % (w,i)
开发者ID:Chris-Meyers,项目名称:OnlinePythonTutor,代码行数:33,代码来源:optKnapsack.py


注:本文中的matrix.Matrix.renderHtml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。