>>> a = np.array([[1,1,2,3,4,5],[1,3,5,7,9]])
>>> a.flatten()
array([[1, 1, 2, 3, 4, 5], [1, 3, 5, 7, 9]], dtype=object)
# flattenは同じ長さの配列にしか使えない。
>>> a = np.array([[1,1,2,3,4,5],[1,3,5,7,9,9]])
>>> a.flatten()
array([1, 1, 2, 3, 4, 5, 1, 3, 5, 7, 9, 9])
>>>
>>> np.amin(a.flatten())
1
>>> np.amax(a.flatten())
9
import heapq
>>> heapq.nsmallest(4, a.flatten())
[1, 1, 1, 2]
>>> heapq.nsmallest(4, np.unique(a.flatten()))
[1, 2, 3, 4]
>>> heapq.nsmallest(4, np.unique(a.flatten()))[-1]
4
最終更新:2017年11月17日 07:03