1.

What Is The Preferred Way To Check For An Empty (zero Element) Array?

Answer»

If you are CERTAIN a VARIABLE is an ARRAY, then use the SIZE attribute. If the variable may be a list or other SEQUENCE type, use len().

The size attribute is preferable to len because:

>>> a = numpy.zeros((1,0))
>>> a.size
0
whereas
>>> len(a)
1

If you are certain a variable is an array, then use the size attribute. If the variable may be a list or other sequence type, use len().

The size attribute is preferable to len because:

>>> a = numpy.zeros((1,0))
>>> a.size
0
whereas
>>> len(a)
1



Discussion

No Comment Found