[Numpy-discussion] how to check type of array?

Robert Kern robert.kern@gmail....
Thu Mar 29 07:49:51 CDT 2012


On Thu, Mar 29, 2012 at 13:47, Derek Homeier
<derek@astro.physik.uni-goettingen.de> wrote:
> On 29 Mar 2012, at 13:54, Chao YUE wrote:
>
>> how can I check type of array in if condition expression?
>>
>> In [75]: type(a)
>> Out[75]: <type 'numpy.ndarray'>
>>
>> In [76]: a.dtype
>> Out[76]: dtype('int32')
>>
>> a.dtype=='int32'?
>
> this and
>
> a.dtype=='i4'
> a.dtype==np.int32
>
> all work. For a more general check (e.g. if it is any type of integer), you can do
>
> np.issubclass_(a.dtype.type, np.integer)

I don't recommend using that. Use np.issubdtype(a.dtype, np.integer) instead.

-- 
Robert Kern


More information about the NumPy-Discussion mailing list