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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:31:12+00:00 2026-05-20T17:31:12+00:00

I have an array of values (between -1.0 and 1.0) that represent intensity (Black

  • 0

I have an array of values (between -1.0 and 1.0) that represent intensity (Black to White). I need a way to map the double values from -1.0 through 1.0 to 0 through 255 and back.

More generalized, I have an array of data and I need to map from the min and max value of the data to a supplied min and max. Basic structure should be like:

private static int[] NormalizeData(double[] data, int min, int max)
{
    var sorted = data.OrderBy(d => d);
    double dataMax = sorted.First();
    double dataMin = sorted.Last();
    int[] ret = new int[data.Length];

    for (int i = 0; i < data.Length; i++)
    {
        ret[i] = (int)data[i];  // Normalization here
    }

    return ret;
}
  • 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-05-20T17:31:13+00:00Added an answer on May 20, 2026 at 5:31 pm

    This works:

    private static int[] NormalizeData(IEnumerable<double> data, int min, int max)
    {
        double dataMax = data.Max();
        double dataMin = data.Min();
        double range = dataMax - dataMin;
    
        return data
            .Select(d => (d - dataMin) / range)
            .Select(n => (int)((1 - n) * min + n * max))
            .ToArray();
    }
    

    The first select normalizes the input to be from 0 to 1 (0 being minimum, 1 being the maximum). The second select takes that normalized number, and maps it to the new minimum and maximum.

    Note that using the LINQ Min() and Max() functions are faster than sorting the input for larger datasets: O(n) vs. O(n * lg(n)).

    Also, if you want to go the other way, then you’ll want it to return doubles instead of ints.

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

Sidebar

Related Questions

I have an array of values that is passed to my function from a
I have an array of double values vals, I need to randomly index into
I have one array. I want that array to retain its value between function
I have an array of short whose values range between 0 and the maximum
Following situation: I have an array with some constant values, which represent ranges. A
So I have an array. The array has string values inside that can change
I have an array of CGColors that I need to display across a path.
I have a large array and would like to find between which array values
I have an array that contains some UTF-8 characters from different languages. Every entry
I have an array of values which is almost, but not quite sorted, with

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.