Possible bug in np.min, np.max, np.ndarray.min, np.ndarray.max
See original GitHub issueWhen 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:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think the
initial
should error if the value is not representable as thedtype
used for computation.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.