python - import pylap as * 报错:NameError: name 'figure' is not defined?
黄舟
黄舟 2017-04-17 16:45:15
0
1
1840

我在运行MIT的python公开课所提供的如下一段代码的时候,Spyder IDE报错

NameError: name 'figure' is not defined

同时,IDE在代码部分给出了错误提示,'from pylab import * unable to detect undefined names'
请教各位,该如何处理这一错误,多谢

补充:有没有可能是这个库没有导进去,但是之前我跑类似的代码,导入pylab是可以正常画图的,中间也没有改变Python或者anaconda的设置,怎么会突然不好用了?作为初学者,真的有些手足无措。

from pylab import * import random, math def flipTrial(numFlips): heads, tails = 0, 0 for i in xrange(0, numFlips): # Comparing traditional range,xrange() save more space coin = random.randint(0, 1) if coin == 0: heads += 1 else: tails += 1 return heads, tails def simFlips(numFlips, numTrials): diffs = [] for i in xrange(0, numTrials): heads, tails = flipTrial(numFlips) diffs.append(abs(heads - tails)) diffs = array(diffs) diffMean = sum(diffs)/len(diffs) diffPercent = (diffs/float(numFlips))*100 percentMean = sum(diffPercent)/len(diffPercent) hist(diffs) axvline(diffMean, color = 'r', label = 'Mean') legend() titleString = str(numFlips) + ' Flips, ' + str(numTrials) + ' Trials' title(titleString) xlabel('Difference between heads and tails') ylabel('Number of Trials') figure() plot(diffPercent) axhline(percentMean, color = 'r', label = 'Mean') legend() title(titleString) xlabel('Trial Number') ylabel('Percent Difference between heads and tails') simFlips(100,100) show()
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

répondre à tous (1)
Peter_Zhu

import pylap as *是什么东西。。。 不应该是from pylab import *么?

    Derniers téléchargements
    Plus>
    effets Web
    Code source du site Web
    Matériel du site Web
    Modèle frontal
    À propos de nous Clause de non-responsabilité Sitemap
    Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!