Dear all,
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'?
thanks!
Chao
--
***
Chao YUE
if type(a) == numpy.ndarray:
...
if a.dtype == 'int32':
...
-=- Olivier
Le 29 mars 2012 07:54, Chao YUE chaoyue...@gmail.com a écrit :
Dear all,
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]:
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
On Thu, Mar 29, 2012 at 13:47, Derek Homeier
de...@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')
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
thanks to all. more than what I need.
cheers,
chao
2012/3/29 Derek Homeier de...@astro.physik.uni-goettingen.de
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)