Python error“TypeError:sort()最多接受2个参数(给定3个)”

2024-04-20 11:58:38 发布

您现在位置:Python中文网/ 问答频道 /正文

在运行来自this tutorial的以下脚本时,我收到“TypeError:sort()最多接受2个参数(给定3个)”:

import numpy as np
from mayavi import mlab

x, y, z = np.ogrid[-10:10:20j, -10:10:20j, -10:10:20j]
s = np.sin(x*y*z)/(x*y*z)
sf = mlab.pipeline.scalar_field(s)
mlab.pipeline.volume(sf)

我使用的python、numpy和mayavi版本分别是3.5.2(Anaconda 4.1.1)、1.11.1和4.5.0。Mayavi是使用以下命令安装的:

^{pr2}$

我试过其他一些mayavi的api,它们工作得很好。有人知道可能出了什么问题吗?下面是完整的回溯。在

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-6743e5b203bd> in <module>()
----> 1 mlab.pipeline.volume(sf)

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\tools\pipe_base.py in the_function(*args, **kwargs)
     36 def make_function(factory_class):
     37     def the_function(*args, **kwargs):
---> 38         factory = factory_class(*args, **kwargs)
     39         return factory._target
     40 

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\tools\pipe_base.py in __init__(self, parent, **kwargs)
    144             self._do_redraw = not scene.disable_render
    145             scene.disable_render = True
--> 146         if issubclass(self._target.__class__, Filter):
    147             self._engine.add_filter(self._target, obj=parent)
    148         else:

C:\Anaconda3\lib\site-packages\traits\trait_types.py in create_default_value(self, *args, **kw)
   2799                 raise TraitError('Unable to locate class: ' + args[0])
   2800 
-> 2801         return klass( *args[1:], **kw )
   2802 
   2803     #: fixme: Do we still need this method using the new style?...

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\core\module.py in __init__(self, **traits)
     56 
     57         # Let the module setup its pipeline.
---> 58         self.setup_pipeline()
     59 
     60     def __get_pure_state__(self):

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\modules\volume.py in setup_pipeline(self)
    305         vp = self._volume_property = tvtk.VolumeProperty()
    306 
--> 307         self._ctf = ctf = default_CTF(0, 255)
    308         self._otf = otf = default_OTF(0, 255)
    309         vp.set_color(ctf)

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\modules\volume.py in default_CTF(x1, x2)
    123                     val_range=(1.0, 1.0),
    124                     n=10,
--> 125                     mode='sqrt')
    126 
    127 

C:\Anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\mayavi\modules\volume.py in make_CTF(x1, x2, hue_range, sat_range, val_range, n, mode)
    101             v = val_range[0] + dval*x
    102             r, g, b, a = [sqrt(c) for c in hsva_to_rgba(h, s, v, 1.0)]
--> 103             ctf.add_rgb_point(mins+x*ds, r, g, b)
    104     elif mode == 'linear':
    105         for i in range(n+1):

c:\anaconda3\lib\site-packages\mayavi-4.5.0-py3.5-win-amd64.egg\tvtk\util\ctf.py in add_rgb_point(self, *args)
    208         ret = super(ColorTransferFunction, self).add_rgb_point(*args)
    209         self.nodes.append(args[0])
--> 210         self.nodes.sort()
    211         return ret
    212 

C:\Anaconda3\lib\site-packages\traits\trait_handlers.py in sort(self, cmp, key, reverse)
   2565     def sort ( self, cmp = None, key = None, reverse = False ):
   2566         removed = self[:]
-> 2567         list.sort( self, cmp = cmp, key = key, reverse = reverse )
   2568 
   2569         if (getattr(self, 'name_items', None) is not None and

TypeError: sort() takes at most 2 arguments (3 given)
*********************************************************************************

Tags: inpyselfpipelineegglibpackagessite