0

So, I have a large number of arrays that I need a mean value for. To try and simplify I'm attempting to use a for-loop, but I'm not sure if this is possible or if it is, how I can name the left-hand of the assignment line. I've tried:

for data in data_list:
    data + _mean = np.mean(data)

This gives a syntax error; can't assign to operator. I feel like that's a lame try, but I'm very new to coding and I'm not sure what I can do on the left-hand side to make each assignment have a unique name.

Thanks for your time!

1
  • Append the values to a list. Commented Sep 28, 2017 at 7:33

1 Answer 1

2

Don't try to give each value a unique name, put them in a list. You can use a list comprehension for this.

means = [np.mean(data) for data in data_list]
Sign up to request clarification or add additional context in comments.

2 Comments

I didn't know I could use 'for data in data_list' outside of a loop statement - thanks! that makes next step easier as well.
Look up Python list comprehensions, they're very powerful and common in Python code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.