_元のチケットhttp://projects.scipy.org/numpy/ticket/1316 on 2009-12-07 @mdboom 、不明に割り当てられました
これは賢明な操作です。 可能であれば、それを機能させるとよいでしょう。
In [25]: x.max()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/wonkabar/data1/builds/betadrizzle/<ipython console> in <module>()
TypeError: cannot perform reduce with flexible type
In [26]: x.min()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/wonkabar/data1/builds/betadrizzle/<ipython console> in <module>()
TypeError: cannot perform reduce with flexible type
In [27]:
これは実行可能である必要があります。 argmax
とargmin
は機能し、 maximum.reduce
を使用せずにこれを実装する簡単な方法を提供する可能性があることに注意してください。
.max
は軸のタプルを取ることができ、 argmax
は単一のaxis
のみを処理できます。 、およびおそらくコピーしてそれらの軸を合体させます。 keepdims
とout
もmax
の署名にありますが、 argmax
の署名にはありません。 どのような種類が関与しますか? 「S」、「U」、「V」?
@jondoの質問 (この時点で約 4 年前ですが、対処する価値があります) には、はい。
フェルドマン博士の不満は、例を使って表現するのが最も適切です。 彼は、「NumPy の .min() および .max() メソッドは数値配列に対して機能し、Python の min() および max() 関数は文字列に対して機能するため、NumPy の .min() および .max() メソッドは文字列の配列に対しては機能しますが、[...]"
これが図です。
import numpy as np
arr_str = np.array(["I'm", "Defying", "Gravity"]) #A wickedly simple array of strings
print(arr_str.max()) #raises "TypeError: cannot perform reduce with flexible type"
#Interestingly, when I just used a native Python list, the error for this line was: "AttributeError: 'list' object has no attribute 'max'"
print(max(arr_str)) #does not raise any kind of error and returns "I'm" no matter where it is in the array of strings above
#This code works as expected
arr_num = np.array([1,2,3,-1])
print(max(arr_num))
フェルドマン博士の問題は、文字列の配列に関するもので、max() ではなく .max() を使用したいというものです。 しかし、柔軟なタイプに関する懸念にそれを拡張できます。 彼は、配列をパラメーターとして渡すときに max() が正常に機能することには言及していませんが、上記の例からわかるように、機能します。
@charris が言ったこと、.argmax() が機能することを確認しました。
コミュニティに対する私の質問は、 @jaimefrio が提起した軸の問題に