-2

I need to calculate this special variance estimate (see pic. below). I have feature matrix X - dxl (d - # features, l - # objects). It's simply to do this in for cycles:


    var_list = []

    for i in range(X.shape[0]):
        for j in range(i + 1, X.shape[0]):
            var_list.append(((X[i, :] - X[j, :]) ** 2).sum())

    variance = np.median(var_list)

But this is ineffective because of python cycle. Is there a way to do it by numpy faster?

Formula for variance:

enter image description here

1
  • Question has actually nothing to do with machine-learning - kindly do not spam irrelevant tags (removed). As for the rest, please post a minimal reproducible example. Commented Feb 18, 2021 at 12:54

1 Answer 1

0

You can use numpy.var() to find the variance faster. You can see the documentation https://numpy.org/doc/stable/reference/generated/numpy.var.html

Sign up to request clarification or add additional context in comments.

2 Comments

Also note that if you want the empirical (or sample variance) you need to use np.var(x, ddof=1). See: stackoverflow.com/questions/41204400/…
But I said, that I need a special variance estimate, which is not implemented in numpy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.