Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6030109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:59:15+00:00 2026-05-23T04:59:15+00:00

How to compare the similarity between two arrays? Say I have: Base Array: [.5,0,0,0,.25,0,0,.25,0,0,0,0]

  • 0

How to compare the similarity between two arrays? Say I have:

Base Array: [.5,0,0,0,.25,0,0,.25,0,0,0,0]

Array 1: [1,0,0,0,1,0,0,1,0,0,0,0]
Array 2: [0,0,1,0,0,0,1,0,0,1,0,0]
Array 3: [1,0,0,0,0,0,0,0,0,0,0,0]

Regarding the arrays above, the answer should be Array 1. The answer is Array 1 because, the array elements are ‘closer’ in structure to the array elements of the base array. Differing from Array 3, .25 is closer to 1 than 0. Another example:

Base Array: [.75,0,0,0,0,0,0,0,.25,0,0,0]

Array 1: [1,0,0,0,1,0,0,1,0,0,0,0]
Array 2: [0,0,1,0,0,0,1,0,0,1,0,0]
Array 3: [1,0,0,0,0,0,0,0,0,0,0,0]

Which in this case, Array 3 should then be the answer.

However, using my current algo (which I will give later), the answer becomes Array 3. Here is what I am using:

for (int i = 0; i < basearray.Length; i++)
{
  temp = (basearray[i] - arrayX[i]);
  dist += temp * temp;
}

So, I think there is something wrong with my algo? Or maybe, I need to use a ‘different’ kind of algorithm and not distance (since essentially, .25 IS closer to 0 than 1, but what I want is otherwise).

Thanks!

UPDATE:

I found the answer! Thanks for all those for the help. Here it is:

float[] pbaseArrX = new float[3];
float[] pcompArrX = new float[3];

float dist1 = 0, dist2 = 0;

for (int i = 0; i < baseArrX.Count; i++)
{
  pbaseArrX[i] = baseArrX[i] / (baseArrX[0] + baseArrX[1] + baseArrX[2]);
}

//Do the following for both compArr1 and compArr2;
for (int i = 0; i < compArrX.Count; i++)
{
  pcompArrX[i] = pcompArrX[i] / (pcompArrX[0] + pcompArrX[1] + pcompArr[2]);
}

//Get distance for both
for (int i = 0; i < pcompArrX.Count; i++)
{
  distX = distX + ((pcompArrX[i] - pbaseArrX[i])^2);
}

//Then just use conditional to determine which is 'closer'
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:59:16+00:00Added an answer on May 23, 2026 at 4:59 am

    It seems like you want to compare the arrays as rays (just direction), but you’re comparing them as vectors (direction and magnitude). I’d suggest comparing the arrays with cosine similarity, which is just the cosine of the angle between the vectors and thus comparison of only their directions. For the arrays presented, the cosine similarity between the base array and array 1 is 0.94 while that with array 2 is 0.82, matching your expectations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Id like to compare two strings in Ruby and find their similarity I've had
What are the usual methods to compare two polygons for similarity? Vertices are in
I have a function which takes two arrays containing the tokens/words of two texts
I'm looking to assess similarity (including case) between two strings and give a value
I need a simple and fast way to compare two images for similarity. I.e.
Anone can compare those two? Any similarity and difference?
I have a function which takes two strings and gives out the cosine similarity
I currently have python code that compares two texts using the cosine similarity measure.
Im writing a php script to compare the similarity of 2 strings. This works
Compare these two methods: void foo() throws SomeSuperException { try { //... } catch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.