[Numpy-discussion] Python 3 and isinstance(np.int64(42), int)

Chris Barker chris.barker at noaa.gov
Fri Jun 19 16:15:26 EDT 2015


On Wed, Jun 17, 2015 at 11:13 PM, Nathaniel Smith <njs at pobox.com> wrote:

>  there's some
> argument that in Python, doing explicit type checks like this is
> usually a sign that one is doing something awkward,


I tend to agree with that.

On the other hand, numpy itself is kind-of sort-of statically typed. But in
that case, if you need to know the type of an array -- check the array's
dtype.

Also:

 >>> a = np.zeros(7, int)
 >>> n = a[3]
 >>> type(n)
<type 'numpy.int64'>

I Never liked declaring numpy arrays with the python types like "int" or
"float" -- in numpy you usually care more about the type, so should simple
use "int64" if you want a 64 bit int. And "float64" if you want a 64 bit
float. Granted, pyton floats have always been float64 (on all platfroms??),
and python ints used to a be a reasonable int type, but now that python
ints are bigInts in py3, it really makes sense to be clear.

And now that I think about it, in py2, int is 32 bit on win64 and 64 bit on
*nix64 -- so you're really better off being explicit with your numpy arrays.

-CHB


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150619/6b889a5d/attachment.html>


More information about the NumPy-Discussion mailing list