If you need an identity for minimization and maximization, a number "I_max"
for which "max(I_max, x) == x" and "I_min" for which "min(I_min, x) == x",
you could use the extreme values of the given integer type.

For instance, if your integer type is np.int64, use

   - I_max = np.iinfo(np.int64).min (which is -9223372036854775808)
   - I_min = np.iinfo(np.int64).max (which is 9223372036854775807).

These numbers are effectively like negative infinity and positive infinity
for the np.int64 integer type because there is no integer value less than
or greater than them, respectively, just as -np.inf and np.inf are the
extreme values of np.float64. (Be explicit in your choice between np.int32
and np.int64, though!)

If these extreme (and ugly-looking) values are the output of your
algorithm, you could catch them and replace them with something else.

But there's no possibility of introducing infinite values to the integer
types because the NumPy numeric types correspond to numeric types in
hardware, which haven't changed in many decades. Every 64 bit-pattern in
np.int64 corresponds to some integer; there's no room to add a new one. It
would have to be a whole new integer type, with different mathematical
rules than hardware instructions provide (so, emulated in software).

I'm not a member of the NumPy team—I'm only asserting the above because I'm
guessing with 99.9999% certainty that this is what they'd say.

Cheers,
-- Jim



On Tue, Nov 22, 2022 at 5:24 PM <2601536...@qq.com> wrote:

> Hi, I am a student and I have very little knowledge about python and
> numpy, so my suggestion may seem really stupid.
> One day I was use numpy to implement Floyd algorithm and then I found the
> data type of np.inf is float, so i can not use min or max function because
> other data type are int. So I wonder whether you can add a new inf whose
> data type is int. Thanks
> _______________________________________________
> 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: jpivar...@gmail.com
>
_______________________________________________
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