I'm trying to use NumPy to check if user input is numerical. I've tried using:
import numpy as np
a = input("\n\nInsert A: ")
if np.isnan(a):
print 'Not a number...'
else:
print "Yep,that's a number"
On its own t works fine, however when I embed it into a function such as in this case:
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)
Then I get a NotImplementationError
saying it isn't implemented for this type, can anyone explain how this is not working?
from numpy import *
, you couldimport numpy as np
and later usenp.isnan()
, etc instead. 2. Don't compare withTrue
directly useif np.isnan(a)
instead. 3.input()
doeseval(raw_input(prompt))
it's most probably not what you want. – Tamatamable