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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:48:52+00:00 2026-06-11T02:48:52+00:00

I have a two-dimensional array of data. I need to average every two rows,

  • 0

I have a two-dimensional array of data. I need to average every two rows, and return the average with an array half of the height. I also need to ignore all NaN values for averaging purposes. For example:

>>> x = numpy.array([[ 1,  nan,  3,  4,  5],
... [ 6,  7,  8,  9, nan],
... [11, 12, 13, 14, nan],
... [16, nan, 18, 19, nan]])

And the function would need to return:

>>> x
array([[3.5,  7,  5.5,  6.5,  5],
[13.5, 12, 15.5, 16.5, nan]])
  • 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-11T02:48:54+00:00Added an answer on June 11, 2026 at 2:48 am

    This should do the trick:

    numpy.ma.average(numpy.ma.masked_invalid(x).reshape(-1, 2, x.shape[-1]), 1)
    

    For me it returns

    masked_array(data =
     [[3.5 7.0 5.5 6.5 5.0]
     [13.5 12.0 15.5 16.5 --]],
                 mask =
     [[False False False False False]
     [False False False False  True]],
           fill_value = 1e+20)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a two dimensional array, which represents columns and rows of data. I
I have a two dimensional array that I need to load data into. I
I have the following three arrays and need to create a new two-dimensional array
I have a two-dimensional array (of Strings) which make up my data table (of
I have two 2-dimensional arrays and want to filter the first array's data using
I have a data file like a two-dimensional array 22950 12 80044 22 02942
I have a array of two dimensions object[,] data; . I want to convert
I have a two-dimensional array. When I print/dump this I get the following My
I have a two dimensional array with the following output Array ( [0] =>
I have a two dimensional array public class TwoDimensions { public static void main(String[]

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.