[Numpy-discussion] help! type 'float64scalar' is not type 'float'

Travis Oliphant oliphant at ee.byu.edu
Thu Aug 3 15:37:33 CDT 2006


Sebastian Haase wrote:
>On Wednesday 02 August 2006 22:43, Travis Oliphant wrote:
>>Sebastian Haase wrote:
>>>Thanks,
>>>I just found
>>>numpy.isscalar() and numpy.issctype()   ?
>>>These sound like they would do what I need - what is the difference
>>>between the two ?
>>
>>Oh, yeah.
>>
>>numpy.issctype works with type objects
>>numpy.isscalar works with instances
>>
>>Neither of them distinguish between scalars and "numbers."
>>
>>If you get errors with isscalar it would be nice to know what they are.
>
>I'm still trying to reproduce the exception, but here is a first comparison
>that - honestly - does not make much sense to me:
>(type vs. instance seems to get mostly the same results  and why is there a
>difference with a string ('12') )

These routines are a little buggy.  I've cleaned them up in SVN to
reflect what they should do.    When the dtype object came into
existence a lot of what the scalar types where being used for was no
longer needed.   Some of these functions weren't updated to deal with
the dtype objects correctly either.

This is what you get now:
 >>> import numpy as N
 >>> N.isscalar(12)

True

 >>> N.issctype(12)

False

 >>> N.isscalar('12')

True

 >>> N.issctype('12')

False

 >>> N.isscalar(N.array([1]))

False

 >>> N.issctype(N.array([1]))

False

 >>> N.isscalar(N.array([1]).dtype)

False

 >>> N.issctype(N.array([1]).dtype)

True

 >>> N.isscalar(N.array([1])[0].dtype)

False

 >>> N.issctype(N.array([1])[0].dtype)

True

 >>> N.isscalar(N.array([1])[0])

True

 >>> N.issctype(N.array([1])[0])

False


-Travis

>>>>N.isscalar(12)
>
>True
>
>>>>N.issctype(12)
>
>True
>
>>>>N.isscalar('12')
>
>True
>
>>>>N.issctype('12')
>
>False
>
>>>>N.isscalar(N.array([1]))
>
>False
>
>>>>N.issctype(N.array([1]))
>
>True
>
>>>>N.isscalar(N.array([1]).dtype)
>
>False
>
>>>>N.issctype(N.array([1]).dtype)
>
>False
>
>  # apparently new 'scalars' have a dtype attribute !
>
>>>>N.isscalar(N.array([1])[0].dtype)
>
>False
>
>>>>N.issctype(N.array([1])[0].dtype)
>
>False
>
>>>>N.isscalar(N.array([1])[0])
>
>True
>
>>>>N.issctype(N.array([1])[0])
>
>True
>
>-Sebastian




More information about the Numpy-discussion mailing list