As said, np.partition should be faster (at most O(n) running time):
np.partition(k.flatten(), -2)[-2]
should return the 2nd largest element. (partition guarantees that the numbered element is in position, all elements before are smaller, and all behind are bigger).