Re: [Numpy-discussion] how to check type of array?
thanks to all. more than what I need. cheers, chao 2012/3/29 Derek Homeier > On 29 Mar 2012, at 14:49, Robert Kern wrote: > > >> 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. > > Sorry, you're right, this works the same way - I had the impression from > the documentation > that tests like np.issubdtype(np.int16, np.integer) would not work, but > they do. > > Cheers, >Derek > > ___ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > -- *** Chao YUE Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL) UMR 1572 CEA-CNRS-UVSQ Batiment 712 - Pe 119 91191 GIF Sur YVETTE Cedex Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16 ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] how to check type of array?
On 29 Mar 2012, at 14:49, Robert Kern wrote: >> 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. Sorry, you're right, this works the same way - I had the impression from the documentation that tests like np.issubdtype(np.int16, np.integer) would not work, but they do. Cheers, Derek ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] how to check type of array?
On Thu, Mar 29, 2012 at 13:47, Derek Homeier 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]: >> >> 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 ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] how to check type of array?
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]: > > 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 ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] how to check type of array?
if type(a) == numpy.ndarray: ... if a.dtype == 'int32': ... -=- Olivier Le 29 mars 2012 07:54, Chao YUE a écrit : > Dear all, > > how can I check type of array in if condition expression? > > In [75]: type(a) > Out[75]: > > In [76]: a.dtype > Out[76]: dtype('int32') > > a.dtype=='int32'? > > thanks! > > Chao > > > -- > > *** > Chao YUE > Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL) > UMR 1572 CEA-CNRS-UVSQ > Batiment 712 - Pe 119 > 91191 GIF Sur YVETTE Cedex > Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16 > > > > > ___ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > > ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] how to check type of array?
Dear all, how can I check type of array in if condition expression? In [75]: type(a) Out[75]: In [76]: a.dtype Out[76]: dtype('int32') a.dtype=='int32'? thanks! Chao -- *** Chao YUE Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL) UMR 1572 CEA-CNRS-UVSQ Batiment 712 - Pe 119 91191 GIF Sur YVETTE Cedex Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16 ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion