[Numpy-discussion] float32 is not a float ?

Bill Spotz wfspotz at sandia.gov
Thu Apr 10 15:22:48 EDT 2008


isinstance() can take a tuple of classes/types as its second argument:

In [1]: isinstance?
Type:           builtin_function_or_method
Base Class:     <type 'builtin_function_or_method'>
String Form:    <built-in function isinstance>
Namespace:      Python builtin
Docstring:
     isinstance(object, class-or-type-or-tuple) -> bool

     Return whether an object is an instance of a class or of a  
subclass thereof.
     With a type as second argument, return whether that is the  
object's type.
     The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut  
for
     isinstance(x, A) or isinstance(x, B) or ... (etc.).

On Apr 10, 2008, at 12:38 PM, Charles Doutriaux wrote:
> Hello,
>
> I guess this maybe "normal" but it breaks a lot of thing when  
> conterting
> from Numeric
>
>>>> a=numpy.ones(5,dtype=numpy.float32)
>>>> isinstance(a[0],float)
> False
>>>>
>
> float64 works...
>
> I can see why one could argue for returning False, but then the
> converter might be too zealous
> things that used to work like:
> if type(item) in [types.IntType, types.FloatType]:
>
> or:
>
> isinstance(item, types.FloatType)
>
> now fail,
>
> should we be concerned? should we consider returning True ?
>
> Thanks,
>
> C.

** Bill Spotz                                              **
** Sandia National Laboratories  Voice: (505)845-0170      **
** P.O. Box 5800                 Fax:   (505)284-0154      **
** Albuquerque, NM 87185-0370    Email: wfspotz at sandia.gov **









More information about the NumPy-Discussion mailing list