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

Derek Homeier derek@astro.physik.uni-goettingen...
Thu Mar 29 07:47:30 CDT 2012


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)

See also "help(np.subdtype)"

Cheers,
					Derek



More information about the NumPy-Discussion mailing list