There are plenty of questions on here where one wants to find the nth smallest element in a numpy array. However, what if you have an array of arrays? Like so:
>>> print matrix
[[ 1. 0.28958002 0.09972488 ..., 0.46999924 0.64723113
0.60217694]
[ 0.28958002 1. 0.58005657 ..., 0.37668355 0.48852272
0.3860152 ]
[ 0.09972488 0.58005657 1. ..., 0.13151364 0.29539992
0.03686381]
...,
[ 0.46999924 0.37668355 0.13151364 ..., 1. 0.50250212
0.73128971]
[ 0.64723113 0.48852272 0.29539992 ..., 0.50250212 1. 0.71249226]
[ 0.60217694 0.3860152 0.03686381 ..., 0.73128971 0.71249226 1. ]]
How can I get the n smallest items out of this array of arrays?
>>> print type(matrix)
<type 'numpy.ndarray'>
This is how I have been doing it to find the coordinates of the smallest item:
min_cordinates = []
for i in matrix:
if numpy.any(numpy.where(i==numpy.amin(matrix))[0]):
min_cordinates.append(int(numpy.where(i==numpy.amin(matrix))[0][0])+1)
Now I would like to find, for example, the 10 smallest items.