[Numpy-discussion] A simple question about type().
Paulo J. S. Silva
rsilva at ime.usp.br
Thu Mar 11 06:19:10 EST 2004
This is a more tricky question.
If I understand well enough. The name "array" in a python section
relates to a factory function that builds arraytype objects. It is not
the name for the array type. For example, if you type:
Which shows that it is a function, not a class object.
There are more subtlety associated to the fact that Numeric does not use
the new class styles as numarray does. Actually if you use numarray
instead of Numeric you'll get a more sensible behavior
>>> import numarray
>>> a = numarray.array([1.,2.,3.])
>>> type(a) is numarray.NumArray
>>> isinstance(a, numarray.NumArray)
Obs: You may consider using a "try: except:" statement instead of always
checking type. In Python is usually better to ask "forgiveness" in a
"except" clause than to ask "permission" by checking types.
Paulo José da Silva e Silva
Professor Assistente do Dep. de Ciência da Computação
(Assistant Professor of the Computer Science Dept.)
Universidade de São Paulo - Brazil
e-mail: rsilva at ime.usp.br Web: http://www.ime.usp.br/~rsilva
Teoria é o que não entendemos o (Theory is something we don't)
suficiente para chamar de prática. (understand well enough to call)
More information about the NumPy-Discussion