[Numpy-discussion] a list of all available integer dtypes

Matthew Brett matthew.brett@gmail....
Fri Aug 9 17:20:15 CDT 2013


Hi,

On Fri, Aug 9, 2013 at 3:17 PM, Robert Kern <robert.kern@gmail.com> wrote:
> On Fri, Aug 9, 2013 at 11:06 PM, Valentin Haenel <valentin@haenel.co> wrote:
>>
>> Hi,
>>
>> I have a quick question: Is there a way to get a list of all available
>> Numpy integer dtypes programatically?
>
> [~]
> |8> def all_dtypes(cls):
> ..>     for sub in cls.__subclasses__():
> ..>         try:
> ..>             sub(0)
> ..>         except TypeError:
> ..>             pass
> ..>         else:
> ..>             yield sub
> ..>         for subsub in all_dtypes(sub):
> ..>             yield subsub
> ..>
>
> [~]
> |10> list(all_dtypes(np.integer))
> [numpy.int8,
>  numpy.int16,
>  numpy.int32,
>  numpy.int64,
>  numpy.int64,
>  numpy.timedelta64,
>  numpy.uint8,
>  numpy.uint16,
>  numpy.uint32,
>  numpy.uint64,
>  numpy.uint64]

or (at least for the standard int dtypes):

np.sctypes['int'] + np.sctypes['uint']

Cheers,

Matthew


More information about the NumPy-Discussion mailing list