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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:17:21+00:00 2026-05-24T12:17:21+00:00

So I have a kindda odd scenario that I cannot get my head arround:

  • 0

So I have a kindda odd scenario that I cannot get my head arround:

I have a outerlist which contains multiple innerlists.
Each innerlist contains multiple DataPoint objects.
Every innerlist contains the same amount of DataPoint objects.
A datapoint has a field called Value which is a double – e.g.:

  • Outerlist
    • Innerlist
      • DataPoint(value=2)
      • DataPoint(value=2)
    • Innerlist
      • DataPoint(value=4)
      • DataPoint(value=5)
    • Innerlist
      • DataPoint(value=3)
      • DataPoint(value=5)

So what I wanna do is to “combine” the innerlists into one List where the value of each DataPoint should be the average of the old values, based on its index in the list – in this case:

  • List
    • DataPoint(3) – ((2+4+3)/3) = 3
    • DataPoint(4) – ((2+5+5)/3) = 4

Is there any neat linq expression that could perform this kind of stuff (Im betting there are :))?


I ended up using the following solution:

var averages = Enumerable.Range(0, outer.First().Count()).Select(i => new DataPoint(outer.Select(l => l[i]).Average(x=>x.Value)));

which outputs IEnumerable, now with average valus – yay!

  • 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-24T12:17:22+00:00Added an answer on May 24, 2026 at 12:17 pm

    Start with an extension method to take a slice of the inner lists:

    public static IEnumerable<double> Slice(
        this IEnumerable<List<DataPoint>> innerLists,
        int index) {
            foreach(var innerList in innerLists) {
                yield return innerList.DataPoints[index].Value;
            }
        }
    }
    

    Then:

    var averages = Enumerable.Range(0, count)
                             .Select(index => outerList.InnerLists.Slice(index))
                             .Select(slice => slice.Average());
    

    I am assuming a hierarchy like this:

    class DataPoint { public double Value { get; set; } }
    
    class InnerList { public List<DataPoint> DataPoints { get; set; } }
    
    class OuterList { public IEnumerable<InnerList> InnerLists { get; set; } }
    

    but the above idea is obviously adaptable to however exactly you have structured your data.

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

Sidebar

Related Questions

I want to have a dialog that looks kinda like this: I thought this
We have a web application (quite a heavy-weight one) that does a whole bundle
We have some initialization code that makes sure that all the needed resources are
I have been give a jar file to use that has a static inner
So I have one date as a string: 2011/06/01 I need to get the
I have written a server and a client both as separate apps. They communicate
I'm kinda new in flash and as3 so this may not be as difficult
My use case is kinda basic. According to the URL a user inputs, I
My question might be kinda confusing but I'll try my best to explain it.
I know this has kinda been asked a million times but I wanted to

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.