也可以进行修补MaskedArray.__float__
以引发异常,这样您就可以看到堆栈跟踪,其中包括您的代码。并且可以在您的代码中进行修补,无需弄乱.../ma/core.py
.
示例squeeze()
:
import numpy as np
from numpy import ma
def raise_me(*args, **kw):
raise Exception('ping')
ma.MaskedArray.squeeze = raise_me
def test():
x = np.array([(1, 1.), (2, 2.)], dtype=[('a',int), ('b', float)])
m = x.view(ma.MaskedArray)
m.squeeze()
def main():
test()
main()
并输出:
Traceback (most recent call last):
File "t.py", line 19, in <module>
main()
File "t.py", line 17, in main
test()
File "t.py", line 13, in test
m.squeeze()
File "t.py", line 6, in raise_me
raise Exception('ping')
Exception: ping
如您所见,它向您显示了m.squeeze()
.