[Numpy-discussion] Python 3 and isinstance(np.int64(42), int)
josef.pktd at gmail.com
josef.pktd at gmail.com
Tue Jun 23 12:33:11 EDT 2015
On Fri, Jun 19, 2015 at 4:15 PM, Chris Barker <chris.barker at noaa.gov> wrote:
> 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.
>
being late checking some examples
>>> a = np.zeros(7, int)
>>> a.dtype
dtype('int32')
>>> np.__version__
'1.9.2rc1'
>>> type(a[3])
<class 'numpy.int32'>
>>> a = np.zeros(7, int)
>>> a = np.array([888888888888888888])
>>> a
array([888888888888888888], dtype=int64)
>>> a = np.array([888888888888888888888888888888888])
>>> a
array([888888888888888888888888888888888], dtype=object)
>>> a = np.array([888888888888888888888888888888888], dtype=int)
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
a = np.array([888888888888888888888888888888888], dtype=int)
OverflowError: Python int too large to convert to C long
Looks like we need to be a bit more careful now.
Josef
Python 3.4.3
>
> -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
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150623/6871a529/attachment.html>
More information about the NumPy-Discussion
mailing list