如何将_reconstruct方法使用到简化的ndyray中?
>>> import numpy as np
>>> v = np.random.random((5))
>>> x = v.__reduce__()
>>> x
>>> (<built-in function _reconstruct>, (<type 'numpy.ndarray'>, (0,), 'b'), (1, (5,), dtype('float64'), False, '\xae^\xe4\x03\xbd\x05\xe8?\x0ei\x97\xe30\x02\xea?F\xb8\x85\xfd\x92\xae\xe1?|\x1c20\xc1\xd3\xe2?\xe8\xfa\xfd\xdc3B\xca?'))
>>> x[0]()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: _reconstruct() takes exactly 3 arguments (0 given)
答案 0 :(得分:0)
在numpy/core/_internal.py
# Build a new array from the information in a pickle.
# Note that the name numpy.core._internal._reconstruct is embedded in
# pickles of ndarrays made with NumPy before release 1.0
# so don't remove the name here, or you'll
# break backward compatibilty.
def _reconstruct(subtype, shape, dtype):
from multiarray import ndarray
return ndarray.__new__(subtype, shape, dtype)