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 7986913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:59:25+00:00 2026-06-04T11:59:25+00:00

I have been looking for away to generate bins for specific dataset (by specifying

  • 0

I have been looking for away to generate bins for specific dataset (by specifying lower band, upper band and number of bins required) using apache common math 3.0. I have looked at Frequency http://commons.apache.org/math/apidocs/org/apache/commons/math3/stat/Frequency.html
but it does not give me what i want.. i want a method that give me frequency for values in an interval ( ex: how many values are between 0 to 5). Any suggestions or ideas?

  • 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-04T11:59:27+00:00Added an answer on June 4, 2026 at 11:59 am

    As far as I know there is no good histogram class in Apache Commons. I ended up writing my own. If all you want are linearly distributed bins from min to max, then it is quite easy to write.

    Maybe something like this:

    public static int[] calcHistogram(double[] data, double min, double max, int numBins) {
      final int[] result = new int[numBins];
      final double binSize = (max - min)/numBins;
    
      for (double d : data) {
        int bin = (int) ((d - min) / binSize);
        if (bin < 0) { /* this data is smaller than min */ }
        else if (bin >= numBins) { /* this data point is bigger than max */ }
        else {
          result[bin] += 1;
        }
      }
      return result;
    }
    

    Edit: Here’s an example.

    double[] data = { 2, 4, 6, 7, 8, 9 };
    int[] histogram = calcHistogram(data, 0, 10, 4);
    // This is a histogram with 4 bins, 0-2.5, 2.5-5, 5-7.5, 7.5-10.
    assert histogram[0] == 1; // one point (2) in range 0-2.5
    assert histogram[1] == 1; // one point (4) in range 2.5-5.
    // etc..
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking for a way to remove an attachment from Jira using
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have been looking at this article about using tasks in C#, and I
A few co-workers and I have been looking at branching in SVN using Eclipse.
I'm using the Azure ACS, and I've been looking for away to get the
I have been considering a range of options to move away form using scriptlets
I have been looking for a way to get rid of the nasty black
I have been looking for a way to allow users to manually override geolocation
I have been looking around for solutions, and tried to implement what is often
I have been looking into CruiseControl configuration recently (I'm a complete CC noob) and

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.