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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:43:32+00:00 2026-06-05T12:43:32+00:00

Python question. I have a list (A) of numpy object arrays (B). I’d like

  • 0

Python question.

I have a list (A) of numpy object arrays (B). I’d like to get the mean of one of the object variables for all the objects in the B array. Right now, I’m just parsing through the B array, summing the variable and dividing it by the number of objects in B. Is there a better or more pythonic way to do this?

It would also be great, if I could get the mean of all objects in the A list (i.e. all objects)

  • 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-05T12:43:33+00:00Added an answer on June 5, 2026 at 12:43 pm

    If you have a numpy array, you can just call the mean method:

    In [24]: import numpy as np
    
    In [25]: b = np.arange(5)
    
    In [26]: b
    Out[26]: array([0, 1, 2, 3, 4])
    
    In [27]: b.mean()
    Out[27]: 2.0
    

    If you have a list of numpy arrays, getting the mean of each numpy is just:

    In [28]: A = [np.arange(i) for i in range(3, 6)]
    
    In [29]: A
    Out[29]: [array([0, 1, 2]), array([0, 1, 2, 3]), array([0, 1, 2, 3, 4])]
    
    In [30]: for B in A: print B.mean()
    1.0
    1.5
    2.0
    

    Or, if you’re trying to get the mean of all the elements (over all elements of B in A), use the sum method:

    In [31]: sum(B.sum() for B in A) / sum(len(B) for B in A)
    Out[31]: 1.5833333333333333
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very basic question here (I've just started with Python). I have a list object.
A python/django beginner's question: I have a datetime object (drive_date), a time object (start_time)
I'm currently developing some things in Python and I have a question about variables
I'm using python, and I have a list of sets, constructed like this: list
This is a slight update to my previous question I have a Python list
I have a question regarding variable linking between objects. Because I'm learning Python programming
(Sorry if it's a trivial question.) I have documents that looks like this (Python
Lets suppose I have a list like this: mylist = [a,b,c,d] To get the
I have a question about python mechanize's proxy support. I'm making some web client
I have question about interpreting strings as packed binary data in C++. In python,

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.