Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29585
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <giuseppe.amatulli@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.010 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'else:': 0.03; 'output': 0.04; 'mrab': 0.05; '%s"': 0.07; 'observation': 0.09; 'rows': 0.09; 'skip:v 70': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'row': 0.16; 'skip:v 60': 0.16; 'subject:array': 0.16; 'subject:looping': 0.16; 'input': 0.18; 'code.': 0.20; 'question.': 0.20; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'file': 0.32; 'skip:d 20': 0.34; 'received:google.com': 0.34; 'thanks': 0.34; 'received:209.85': 0.35; 'add': 0.36; 'but': 0.36; 'should': 0.36; 'possible': 0.37; 'skip:v 20': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'received:209.85.214': 0.39; 'from:no real name:2**0': 0.60; 'skip:u 10': 0.60; 'first': 0.61; 'skip:n 10': 0.63; 'more': 0.63; 'here': 0.65; 'sum': 0.66; 'received:209.85.214.184': 0.84; 'received:mail- ob0-f184.google.com': 0.84; 'subject:dic': 0.84; 'faster.': 0.91; 'average': 0.93 |
| Newsgroups | comp.lang.python |
| Date | Thu, 20 Sep 2012 16:35:15 -0700 (PDT) |
| In-Reply-To | <mailman.971.1348169395.27098.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=137.216.206.11; posting-account=X69PegoAAADSdW7HHxG-TPWTj8wMt3Gs |
| References | <007b2d71-3355-4085-b84f-204834b2c8d0@googlegroups.com> <505B6A00.10308@mrabarnett.plus.com> <CALwzid=HowMzWmgiU2+2Gu4opxWu0Hx-iOFRZZcXi=BAdKVfrw@mail.gmail.com> <mailman.971.1348169395.27098.python-list@python.org> |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| X-Google-IP | 137.216.206.11 |
| MIME-Version | 1.0 |
| Subject | Re: looping in array vs looping in a dic |
| From | giuseppe.amatulli@gmail.com |
| To | comp.lang.python@googlegroups.com |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Message-ID | <mailman.982.1348184123.27098.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1348184123 news.xs4all.nl 6986 [2001:888:2000:d::a6]:37572 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:29585 |
Show key headers only | View raw
Hi Ian and MRAB
thanks to you input i have improve the speed of my code. Definitely reading in dic() is faster. I have one more question.
In the dic() I calculate the sum of the values, but i want count also the number of observation, in order to calculate the average in the end.
Should i create a new dic() or is possible to do in the same dic().
Here in the final code.
Thanks Giuseppe
rows = dsCategory.RasterYSize
cols = dsCategory.RasterXSize
print("Generating output file %s" %(dst_file))
start = time()
unique=dict()
for irows in xrange(rows):
valuesRaster=dsRaster.GetRasterBand(1).ReadAsArray(0,irows,cols,1)
valuesCategory=dsCategory.GetRasterBand(1).ReadAsArray(0,irows,cols,1)
for icols in xrange(cols):
if ( valuesRaster[0,icols] != no_data_Raster ) and ( valuesCategory[0,icols] != no_data_Category ) :
row = valuesCategory[0, icols],valuesRaster[0, icols]
if row[0] in unique :
unique[row[0]] += row[1]
else:
unique[row[0]] = 0+row[1] # this 0 was add if not the first observation was considered = 0
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
looping in array vs looping in a dic giuseppe.amatulli@gmail.com - 2012-09-20 11:31 -0700
Re: looping in array vs looping in a dic MRAB <python@mrabarnett.plus.com> - 2012-09-20 20:09 +0100
Re: looping in array vs looping in a dic Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-20 13:28 -0600
Re: looping in array vs looping in a dic Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-20 13:29 -0600
Re: looping in array vs looping in a dic giuseppe.amatulli@gmail.com - 2012-09-20 16:35 -0700
Re: looping in array vs looping in a dic MRAB <python@mrabarnett.plus.com> - 2012-09-21 00:58 +0100
Re: looping in array vs looping in a dic giuseppe.amatulli@gmail.com - 2012-09-20 16:35 -0700
csiph-web