I read this question
python: how to identify if a variable is an array or a scalar
but when using the following code I get a false on an np.array
as can be demonstrated below.
import collections
isinstance(np.arange(10), collections.Sequence)
# returns false
I find it a bit annoying that I can't do len(1)
and simply get 1
.
The only work around I can think of is a try except
statement such as the following:
a = 1
try:
print len(a)
except TypeError:
print 1
Is there a more Pythonic way to do this?