Am Sa., 25. Dez. 2021 um 10:03 Uhr schrieb Lev Maximov <lev.maxi...@gmail.com>:
>
> https://axil.github.io/numpy-data-types.html

> Speaking of zero-dimensional arrays more realistic example where you can run 
> into them is when you iterate over a numpy array with nditer:

There seems to be missing an "a" before "more".

Overflow warning: Instead of

>>> np.array([2**63–1])[0] + 1
FloatingPointError: overflow encountered in longlong_scalars

on my machine it runs::

>>> numpy.array([2 ** 63 - 1])[0] + 1
<stdin>:1: RuntimeWarning: overflow encountered in long_scalars

There are also some more significant unclarities remaining:

1.  The RuntimeWarning is issued *only once*:

>>> b = numpy.array([2 ** 63 - 1])[0]
>>> b + 1
<stdin>:1: RuntimeWarning: overflow encountered in long_scalars
-9223372036854775808
>>> b + 1
-9223372036854775808

2.  And I do not get the the difference here:

>>> a = numpy.array(2 ** 63 - 1)
>>> b = numpy.array([2 ** 63 - 1])[0]
>>> a.dtype, a.shape
(dtype('int64'), ())
>>> b.dtype, b.shape
(dtype('int64'), ())
>>> with numpy.errstate(over='raise'):
...     a + 1
...
-9223372036854775808
>>> with numpy.errstate(over='raise'):
...     b + 1
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
FloatingPointError: overflow encountered in long_scalars

The only apparent difference I can get hold of is that:

>>> a[()] = 0
>>> a
array(0)

but:

>>> b[()] = 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'numpy.int64' object does not support item assignment

While writing this down I realise that *a* is a zero-dimensional
array, while *b* is an int64 scalar.  This can also be seen from the
beginning:

>>> a
array(9223372036854775807)
>>> b
9223372036854775807

So, unclarity resolved, but maybe I am not the only one stumbling over this.

Maybe the idiom ``>>> c = numpy.int64(2 ** 63 - 1)`` can be used?  I
never used this, so I am unsure about the exact semantics of such a
statement.

I am stopping studying your document here.  Might be that I continue later.

Friedrich
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to