question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible bug in np.min, np.max, np.ndarray.min, np.ndarray.max

See original GitHub issue

When using np.min or np.max by setting the value of initial to np.inf and -np.inf, respectively, the output is not what was expected. Perhaps I’m missing something, sorry if this is not actually a bug.

Reproducing code example:

In[44]: np.array([-10,20,30,-25]).min(initial=np.inf)
Out[44]: -9223372036854775808
In[45]: np.array([-10,20,30,-25]).min(initial=-np.inf)
Out[45]: -9223372036854775808
In[46]: np.array([-10,20,30,-25]).max(initial=np.inf)
Out[46]: 30
In[47]: np.array([-10,20,30,-25]).max(initial=-np.inf)
Out[47]: 30
In[48]: np.min([-10,20,30,-25], initial=np.inf)
Out[48]: -9223372036854775808
In[49]: np.min([-10,20,30,-25], initial=-np.inf)
Out[49]: -9223372036854775808
In[50]: np.max([-10,20,30,-25], initial=np.inf)
Out[50]: 30
In[51]: np.max([-10,20,30,-25], initial=-np.inf)
Out[51]: 30

Numpy/Python version information:

1.18.1 3.7.6 | packaged by conda-forge | (default, Mar 23 2020, 23:03:20) [GCC 7.3.0]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
mattipcommented, Apr 4, 2020

I think the initial should error if the value is not representable as the dtype used for computation.

0reactions
sebergcommented, Nov 19, 2022

I changed this and now it raises an error. If you were to pass np.float64(np.inf) you would at the very least get an “invalid value” warning (not quite sure, didn’t try). So closing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug in Numpy ndarray min/max method - Stack Overflow
Am I using the wrong function? I know there's amax and max , as well as the package level numpy. max , but...
Read more >
numpy.ndarray.max — NumPy v1.24 Manual
Return the maximum along a given axis. Refer to numpy.amax for full documentation. ... Created using Sphinx 5.3.0.
Read more >
Avian's Blog: The NumPy min and max trap - Tablix
It appears that NumPy thinks axis zero is a reasonable choice for a zero-dimensional input and doesn't complain.
Read more >
The min() and max() functions of ndarray - Pythontic.com
min () and max() functions of numpy.ndarray() provides the minimum and maximum values along the specified axis. An example with a 3-dimensional array...
Read more >
Supported NumPy features - Numba
NumPy arrays are directly supported in Numba. Access to Numpy arrays is very efficient, as indexing is lowered to direct memory accesses when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found