473,657 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to break down a python list

27 New Member
Hello all!

I have a variable name "thelist" which is a list of 100,000 elements. I was wondering how I can make two new lists of the average value and standard deviation from this. For example if my list is [1,2,3,4,5,6,7,8 ,9,10] then the new list would be the average of the every 5 numbers, endeing up looking like [average(1,2,3,4 ,5),average(6,7 ,8,9,10)]=[3,8]. I am very comfortable using numpy to get the average and standard deviation values. I am just having trouble breaking the initial list down. I'm not sure if this is what indexing is.

Any help would really be appreciated,
Thank YOU!
Nov 24 '10 #1
4 3522
ronparker
27 New Member
I am also curious to know if there is a simple way to see how many positive numbers there are in each 100 segments of the bit 100,000 list. Thank YOU!
Nov 24 '10 #2
dwblas
626 Recognized Expert Contributor
For example if my list is [1,2,3,4,5,6,7,8 ,9,10] then the new list would be the average of the every 5 numbers
You can use two for loops. With the outer loop, set the step value at 5 or whatever the increment. The inner loop adds each of the 5 numbers together.
Expand|Select|Wrap|Line Numbers
  1. test_list = range(1, 51)
  2. for outer in range(0, len(test_list), 5):
  3.     total = 0
  4.     for inner in range(5):
  5.         total += test_list[outer+inner]
  6.         print test_list[outer+inner],
  7.     print "\n", float(total)/5 
Nov 24 '10 #3
omg, awful!

Expand|Select|Wrap|Line Numbers
  1. lambda lst, ln: [ lst[i:i+ln] for i in range(0, len(lst), ln) ]
Nov 24 '10 #4
bvdet
2,851 Recognized Expert Moderator Specialist
What's the lambda for?

Expand|Select|Wrap|Line Numbers
  1. >>> data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
  2. >>> n = 5
  3. >>> def average(seq):
  4. ...     return sum(seq)/float(len(seq))
  5. ... 
  6. >>> [average(data[i:i+n]) for i in range(0, len(data), n)]
  7. [3.0, 8.0, 13.0]
  8. >>> data = [1,2,-3,4,5,6,-7,8,-9,10,11,-12,-13,-14,15]
  9. >>> [sum([1 for item in data[i:i+n] if item>0]) for i in range(0, len(data), n)]
  10. [4, 3, 2]
  11. >>> 
Nov 25 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2208
by: Dave Brueck | last post by:
Is anybody else having problems sending email to python-list@python.org? About 48 hours ago or so my posts stopped making it to the list (I usually post via the mailing list rather than to the Usenet group). I tried unsubscribing and resubscribing to the list, but that turned out to be a mistake because once the list server sent me the email to confirm my subscription request, my reply email confirming it got ignored too!
1
1416
by: Dave Brueck | last post by:
The other day I stopped receiving emails from python-list (although python-dev kept going just fine). This morning I decided to investigate and the Mailman page for python-list had my address disabled due to too many bounced mails, even though (1) the mail server here hasn't suffered any network outages or downtime lately and (2) python-dev emails continued to arrive without problems. What's worse, when I looked at the list of...
3
1337
by: Brad Clements | last post by:
I have not seen any new posts in gmane.comp.python.general since 6/18/2004. However when I post to gmane, that post seems to make it out to the python list. Does anyone know if its a gmane problem, or a general news to python-list problem?
0
1551
by: Heiko Wundram | last post by:
Hi all, esp. list admins! Why is it that I always get bounces saying my mails have suspicious headers lately when I post to python-list? This only happens when I reply to myself (as I just did, because my reply to "Partitions of an Integer" contained two little mistakes, which I wanted to correct in a followup...) I've never had this before mail.python.org switched to XS4ALL... If any of the mail admins happen to be reading this, it'd...
5
1942
by: He, Aspk | last post by:
My thunderbir cant connect to comp.lang.python as the python.org page saying.
9
1728
by: Terry Reedy | last post by:
For a couple of years, I have been reading and posting and posting to python-list and c.l.p via gmane.news.orgs gmane.comp.python.general group. Today I got this from 'python-list-bounces', which I presume is a 'machine' rather than a 'human' address. --------------------------- Your mail to 'Python-list' with the subject Re: how to join two Dictionary together?
8
6144
by: jerry.levan | last post by:
Hi, I have a file that contains a "tcl" list stored as a string. The list members are sql commands ex: { begin { select * from foo where baz='whatever'} {select * from gooble } end { insert into bar values('Tom', 25) } }
0
756
by: J. Cliff Dyer | last post by:
On Fri, 2008-04-18 at 17:25 +0200, python-list-request@python.org wrote: of the major issues that prompted the Py3K push in the first place. The accumulated cruft had gotten heavy, and was slowing python down. Py3K is deliberately conservative, so that the transition will be as painless as possible, but strips away the warts that were slowing things down. Having print as a statement meant it was difficult to add functionality there. ...
0
993
by: Gareth Owen | last post by:
On Monday 12 May 2008 14:55:06 python-list-request@python.org wrote: If timing is critical, try using a semaphore technique.
18
2380
by: Grant Edwards | last post by:
Could whoever is responsible for the gateway that is grabbing my postings off of Usenet and e-mailing them out please fix the headers in the mail messages so that I don't get the bounce messages? While you're at it, might as well fix it for everybody else too. ;) Its a bit rude to send out mass e-mail messages with headers faked up so that the bounce messages go to somebody else.
0
8411
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8323
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8613
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7351
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.