-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
.max() and .min() don't work on arrays of type 'S' and 'U' (Trac #1316) #1914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This should be doable. Note that |
|
…s suggested in issue numpy#1914 . I've added function _String_Min_Or_Max to methods.c and updated functions array_min and array_max to handle string ndarrays. One can launch this functions with arguments - keepdims, out and axis (which can be a tuple to enable multidimensional reductions). The solution is based on PyArray_ArgMin and PyArray_Argmax functs, as suggested in issue. I've also created class TestMax in core/tests/test_multidimensional.py in which several tests are placed.
Is this the same problem as described in nr. 9 here? In [1]: np.array([['dd', 'de', 'cc'], ['ae', 'be', 'hf']]).max(axis=0)
TypeError: cannot perform reduce with flexible type |
To @jondo 's question (nearly 4 years ago at this point but worth addressing), yes. Dr Feldman's complaint is best expressed with an example. He says "Because NumPy's .min() and .max() methods work for numeric arrays, and Python's min() and max() functions work for strings, one might reasonably expect NumPy's .min() and .max() methods to work for arrays of strings, but they don't[...]" Here's an illustration:
Dr Feldman's issue as he stated is about arrays of strings and wanting to use .max() rather than max(); but we can expand it to a concern about any flexible type. Note that he does not mention that max() works just fine when we pass the array in as a parameter, but as you can see from the example above, it does work. I verified what @charris said, that .argmax() does work. My question for the community would be: is this enough of a problem (having to use either max(list) or list.argmax) that it's worth diving into the axis issues that @jaimefrio brought up? |
This is now possible a plausible project by basing the work on gh-21041. |
Original ticket http://projects.scipy.org/numpy/ticket/1316 on 2009-12-07 by @mdboom, assigned to unknown.
This is a sensible operation. It would be nice to make it work if possible.
The text was updated successfully, but these errors were encountered: