2

Imagine you have a value that might or might not be one of the NumPy dtypes. How would you write a function that checks which is the case?

def is_numpy(value):
    # how to code?
jrothenbuhler
  • 454
  • 1
  • 4
  • 13

1 Answers1

2

One way I've found that works was used by Mike T in his answer to Converting numpy dtypes to native python types:

def is_numpy(value):
    return hasattr(value, 'dtype')

I'm not sure whether or not this is the preferred method, but it's relatively simple and clean.

Community
  • 1
  • 1
jrothenbuhler
  • 454
  • 1
  • 4
  • 13