问题xxx: TypeError: __randomstate_ctor() takes from 0 to 1 positional arguments but 2 were given

背景是用了多台电脑跑模型,结果发现复制过来的MLP模型的*.pickle文件读不好((

报错如下:

bclf = pickle.load(f_bclf)

TypeError: __randomstate_ctor() takes from 0 to 1 positional arguments but 2 were given

CSDN上没找到怎么解决,github上这篇帮助很大

https://github.com/numpy/numpy/issues/14210

大体来说,是numpy/random版本问题,服务器numpy1.24.2, 办公室电脑numpy1.22.2,前者做的pickle.dump(*),后者来pickle.load(*), __randomstate_ctor()的参数个数超了。pycharm里手动更新了一下(好像)没好。

看代码的话差别大概这样:

用来dump的:*\site-packages\numpy\random\_pickle.py

def __randomstate_ctor(bit_generator_name="MT19937",

bit_generator_ctor=__bit_generator_ctor):

"""

Pickling helper function that returns a legacy RandomState-like object

Parameters

----------

bit_generator_name : str

String containing the core BitGenerator's name

bit_generator_ctor : callable, optional

Callable function that takes bit_generator_name as its only argument

and returns an instantized bit generator.

Returns

-------

rs : RandomState

Legacy RandomState using the named core BitGenerator

"""

return RandomState(bit_generator_ctor(bit_generator_name))

用来load的:*\site-packages\numpy\random\_pickle.py

def __randomstate_ctor(bit_generator_name='MT19937'):

"""

Pickling helper function that returns a legacy RandomState-like object

Parameters

----------

bit_generator_name : str

String containing the core BitGenerator

Returns

-------

rs : RandomState

Legacy RandomState using the named core BitGenerator

"""

if bit_generator_name in BitGenerators:

bit_generator = BitGenerators[bit_generator_name]

else:

raise ValueError(str(bit_generator_name) + ' is not a known '

'BitGenerator module.')

return RandomState(bit_generator())

前面的__generator_ctor之类基本上也是这样,做个统一就好了,我直接贴过去了((

啊好像就行了www

你可能感兴趣的:(numpy,python)