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.

Signatures and behaviors of `argmax` and `argmin` are incompatible with NumPy

See original GitHub issue

First, for the signature: In CuPy the signature for argmax() and argmin() is

cupy.argm*(a, axis=None, dtype=None, out=None, keepdims=False)

But in NumPy it’s

numpy.argm*(a, axis=None, out=None)

That is, dtype and keepdims should be removed.

Second, for the behavior: In CuPy the axis could be a tuple, but in Numpy it can only be an integer:

>>> import cupy as cp
>>> a = cp.arange(60).reshape(3,4,5)
>>> a.argmax(axis=(0,1))
array([11, 11, 11, 11, 11], dtype=int64)
>>> 
>>> import numpy as np
>>> a = np.arange(60).reshape(3,4,5)
>>> a.argmax(axis=(0,1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'tuple' object cannot be interpreted as an integer

I think both are easy to fix. Just add a few guards prior to calling the actual workhorses.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
niboshicommented, Dec 24, 2019

We don’t have to remove any arguments? Then, #2872 fixes the remaining issue (dtype argument of argmin/argmax).

1reaction
toslunarcommented, Dec 24, 2019

Issue numpy/numpy#8710: “Add keepdims argument to argmin and argmax”

Read more comments on GitHub >

github_iconTop Results From Across the Web

numpy: what is the logic of the argmin() and argmax() functions?
By adding the axis argument, NumPy looks at the rows and columns individually. When it's not given, the array a is flattened into...
Read more >
NumPy 1.22.0 Release Notes
When a function that respects numpy.ndarray subclasses is vectorized using numpy.vectorize , the vectorized function will now be subclass-safe also for cases ...
Read more >
Supported NumPy features - Numba documentation
The following methods of NumPy arrays are supported: argmax() ( axis keyword argument supported). argmin() ( ...
Read more >
What's New — pandas 0.23.2 documentation - PyData |
With NumPy 1.15 and pandas 0.23.1 or earlier, numpy.all() will no longer ... We've deprecated the current behavior of Series.argmax and Series.argmin ....
Read more >
What's New - Xarray
Fix incompatibility with numpy 1.20. ... DataArray.argmin() and DataArray.argmax() now support sequences of 'dim' arguments, and if a sequence is passed ...
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