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

  • Home
  • SEARCH
  • 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 8513895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:42:39+00:00 2026-06-11T04:42:39+00:00

I guess this would be more maths than C#. I’ve got an array of

  • 0

I guess this would be more maths than C#. I’ve got an array of float values, where most values belong to one of the few tightly packed ranges. Here’s an example (Lower Limit=0,Upper Limit=612):

3.4,5.0,6.1, 
144.0,144.14,145.0,147.0, 
273.77,275.19,279.0, 
399.4,399.91,401.45, 
533.26,537.0,538.9

This is a single array of 16 values, just separated them to show those “groups”. What I need to do is to somehow group them, either using Linq, or a manual loop or whatever, so that those close values fall in a single group.

A simple math operation like dividing by 10 (or 100) won’t work, because 399 would fall in a different group than 401 (4th group in the above example). Another approach would be to create a histogram of some kind, but I’m looking for something simple here. Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 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-06-11T04:42:41+00:00Added an answer on June 11, 2026 at 4:42 am

    Just an another idea of a clustering with using GroupBy with a custom comparer

    var numbers = new float[]
        {
           3.4f, 5.0f, 6.1f, 144.0f, 144.14f, 145.0f, 
           147.0f, 273.77f, 275.19f, 279.0f, 399.4f, 399.91f, 401.45f,
           49, 50, 51,
           533.26f, 537.0f, 538.9f
        };
    
    foreach (var group in numbers.GroupBy(i => i, new ClosenessComparer(4f)))
        Console.WriteLine(string.Join(", ", group));
    

    And the custom ClosenessComparer:

    public class ClosenessComparer : IEqualityComparer<float>
    {
        private readonly float delta;
    
        public ClosenessComparer(float delta)
        {
            this.delta = delta;
        }
    
        public bool Equals(float x, float y)
        {
            return Math.Abs((x + y)/ 2f - y) < delta;
        }
    
        public int GetHashCode(float obj)
        {
            return 0;
        }
    }
    

    And the output:

    1: 3,4 5 6,1
    2: 144 144,14 145 147
    3: 273,77 275,19 279
    4: 399,4 399,91 401,45
    6: 49 50 51
    5: 533,26 537 538,9
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I guess this is more a design pattern question than a SQL one. In
I guess another way to phrase this would be Is there a class like
I knew this day would come, so I guess it is here. (P.S. I
I guess this question that would have already been asked here. I searched but
This is more of a fun experiment than an issue, I'm more curious as
It seems like using this function would be more portable or reliable, because the
I'm trying to 'group' a string into segments, I guess this example would explain
I guess this is a simple question. I need to do something like this:
I guess this is similar to what Facebook does, but...I haven't worked out how
I guess this is kind of an odd question but I have tried setting

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.