I have to compute a similarity measure on several thousands of uneven arrays. 
The naive implementation is basically in O(n²) and it's taking too long for the number of arrays I have.
Hopefully, I'm interested only in the similarity for the most similar arrays. 
So far I used the sci-kit learn implementation of `NearestNeighbors` which does the job for arrays with the same number of dimensions. However, `NearestNeighbors` is based on a KD-tree and I think it's not possible to apply this algorithm for uneven arrays.

Is there any alternative for arrays of different dimensions?

Here is a code snippet summarizing the problem:

```
import numpy as np

from sklearn.neighbors.unsupervised import NearestNeighbors

def partial_mse(a: np.array, b: np.array) -> float:
    def mse(a: np.array, b: np.array) -> float:
        mse = (np.square(a - b)).mean()
        return -np.sqrt(mse)

    if a.size == b.size:
        return mse(a, b)

    # a is always the bigger one
    if a.size < b.size:
        a, b = b, a

    partial_mse = [mse(a[i:i + b.size], b) for i in range(a.size - b.size + 1)]
    return np.max(partial_mse)

uneven_array = np.array([[1, 2, 3, 4], [3, 4], [3, 2, 6], [2, 1, 3], [3]])
even_array = np.array([[1, 2, 3, 4], [3,2, 4, 1], [3, 2, 6, 1], [2, 6, 1, 3], [3, 5, 2, 0]])

nnfit = NearestNeighbors(n_neighbors=2, algorithm='auto', n_jobs=-1,
                         metric=partial_mse, metric_params={}).fit(uneven_array)

```

```
ValueError: setting an array element with a sequence.

```