_Original ticket http://projects.scipy.org/numpy/ticket/1316 on 2009-12-07 by @mdboom , assigned to unknown._
์ด๊ฒ์ ํ๋ช ํ ์์ ์ ๋๋ค. ๊ฐ๋ฅํ๋ฉด ์๋ํ๋๋กํ๋ ๊ฒ์ด ์ข์ ๊ฒ์ ๋๋ค.
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'?
์ด๊ฒ์ nr ์์ ์ค๋ช ํ ๊ฒ๊ณผ ๋์ผํ ๋ฌธ์ ์ ๋๊น?
In [1]: np.array([['dd', 'de', 'cc'], ['ae', 'be', 'hf']]).max(axis=0)
TypeError: cannot perform reduce with flexible type
@jondo ์ ์ง๋ฌธ์ (๊ฑฐ์ 4 ๋ ์ ์ด ์์ ์์ ์ธ๊ธ ํ ๊ฐ์น๊ฐ ์์), ๊ทธ๋ ์ต๋๋ค.
Feldman ๋ฐ์ฌ์ ๋ถ๋ง์ ์๋ฅผ ๋ค์ด ๊ฐ์ฅ ์ ํํ๋ฉ๋๋ค. ๊ทธ๋ "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))
Feldman ๋ฐ์ฌ์ ๋ฌธ์ ๋ ๋ฌธ์์ด ๋ฐฐ์ด์ ๊ดํ ๊ฒ์ด๋ฉฐ max () ๋์ .max ()๋ฅผ ์ฌ์ฉํ๋ ค๋ ๊ฒ์ ๋๋ค. ๊ทธ๋ฌ๋ ์ฐ๋ฆฌ๋ ๋ชจ๋ ์ ์ฐํ ์ ํ์ ๋ํ ์ฐ๋ ค๋ก ํ์ฅ ํ ์ ์์ต๋๋ค. ๊ทธ๋ ๋ฐฐ์ด์ ๋งค๊ฐ ๋ณ์๋ก ์ ๋ฌํ ๋ max ()๊ฐ ์ ์๋ํ๋ค๊ณ ์ธ๊ธํ์ง ์์์ง๋ง ์์ ์์์ ๋ณผ ์ ์๋ฏ์ด ์๋ํฉ๋๋ค.
@charris ๊ฐ .argmax ()๊ฐ ์๋ํ๋ค๋ ๊ฒ์ ํ์ธํ์ต๋๋ค.
์ปค๋ฎค๋ํฐ์ ๋ํ ๋ด ์ง๋ฌธ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. @jaimefrio๊ฐ ์ ๊ธฐ ํ ์ถ ๋ฌธ์ ๋ฅผ