我正在尝试使用 NumPy 检查用户输入是否为数字。我试过使用:
import numpy as np
a = input("\n\nInsert A: ")
if np.isnan(a):
print 'Not a number...'
else:
print "Yep,that's a number"
t 本身工作正常,但是当我将它嵌入到函数中时,例如在这种情况下:
import numpy as np
def test_this(a):
if np.isnan(a):
print '\n\nThis is not an accepted type of input for A\n\n'
raise ValueError
else:
print "Yep,that's a number"
a = input("\n\nInsert A: ")
test_this(a)
然后我得到一个NotImplementationError
说法,它没有针对这种类型实现,任何人都可以解释它是如何不起作用的吗?