min/max of empty arrays
See original GitHub issueA similar issue was raised in #2670, however the edge case of (0, ) shape is still not covered. I can go around it with checking for non-zero length in an if
statement, but it would be more practical if np.min
could handle this, too.
In [24]: [np.min(param[x][1]) for x in fields]
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-24-076aa74e3684> in <module>()
----> 1 [np.min(param[x][1]) for x in fields]
/data/wts/pipeline64/python/lib/python2.6/site-packages/numpy/core/fromnumeric.pyc in amin(a, axis, out)
1893 except AttributeError:
1894 return _wrapit(a, 'min', axis, out)
-> 1895 return amin(axis, out)
1896
1897
ValueError: zero-size array to minimum.reduce without identity
In [25]: param[x]
Out[25]:
{1: array([], dtype=float64),
2: array([], dtype=float64),
3: array([], dtype=float64),
4: array([], dtype=float64)}
In [26]: param[x][1].shape
Out[26]: (0,)
Issue Analytics
- State:
- Created 9 years ago
- Comments:20 (19 by maintainers)
Top Results From Across the Web
javascript - Getting empty array when calculating min and max
I'm trying to write a function that used reduce() method to find the min and max value in the array, and then returns...
Read more >CodingBat minMax
Return both the smallest and the largest elements ({min, max}) in a non-empty array of integers. We'll use the convention of considering only...
Read more >JavaScript find min/max from array of objects - Daily Dev Tips
How to find the min or max value from an array of objects. ... the following error: TypeError: Reduce of empty array with...
Read more >Steps to make array empty by removing maximum and its right ...
Select the max number in the array and delete that number including all the numbers to its right side in the array.
Read more >ReArrange Min/Max - Xavier Carty - Medium
Today we are going to talk about rearranging values in array min and max form. In this solution, we first create an empty...
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 FreeTop 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
Top GitHub Comments
reduceat
doesn’t even use it’s identity - don’t open that can of worms. There’s another issue about that elsewhereaccumulate
perhaps doesn’t need it?np.minimum.accumulate([])
is already well-definedaccumulateat
doesn’t existOK, I see your point, however can’t see why it behaves differently for different empty arrays (e.g. getting the minimum for
axis=1
andaxis=0
in #2670’s example). Both are empty, still the minimum will be either an empty array or aValueError
.To be honest, I would be most happy with a
nan
as a result tomin([])
, at least it seems more reasonable than an error.