Example data:
array(
[[ 1., 1.],
[ 2., 1.],
[ 0., 1.],
[ 0., 0.],
[ 0., 0.]])
with a desired result of
>>> [0.,0.]
ie) The most common pair.
Approaches that don't seem to work:
Using statistics
as numpy arrays are unhashable.
Using scipy.stats.mode
as this returns the mode over each axis, eg) for our example it gives
mode=array([[ 0., 1.]])
You can do this efficiently with numpy
using the unique
function:
pairs, counts = np.unique(a, axis=0, return_counts=True)
print(pairs[counts.argmax()])
Returns: [ 0. 0.]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With