Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(of': 0.07; '__name__': 0.07; 'data:': 0.07; 'main()': 0.07; 'subject:help': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'spelling': 0.09; 'teh': 0.09; 'def': 0.10; 'ignore': 0.13; 'passing': 0.15; "'__main__':": 0.16; 'add,': 0.16; 'dot,': 0.16; 'looping': 0.16; 'numpy': 0.16; 'oct': 0.16; 'prog': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'element': 0.17; 'skip': 0.17; 'input': 0.18; 'code.': 0.20; 'math': 0.20; 'define': 0.20; 'written': 0.20; 'all,': 0.21; 'import': 0.21; 'supposed': 0.21; 'form:': 0.22; 'elements': 0.23; 'script': 0.24; 'reaches': 0.27; "doesn't": 0.28; 'header:X-Complaints-To:1': 0.28; 'run': 0.28; 'diagnose': 0.29; 'loop,': 0.29; 'points': 0.29; 'fri,': 0.30; 'expect': 0.31; 'code': 0.31; 'point': 0.31; 'running': 0.32; 'print': 0.32; '+0200,': 0.33; 'url:home': 0.33; 'to:addr:python- list': 0.33; 'another': 0.33; 'minimum': 0.34; 'or,': 0.34; 'data,': 0.35; 'process,': 0.35; 'next': 0.35; 'received:org': 0.36; 'but': 0.36; 'data.': 0.36; 'totally': 0.36; "didn't": 0.36; 'subject:with': 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'execute': 0.37; 'previous': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'easier': 0.38; 'mean': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'space': 0.39; 'header:Received:5': 0.40; 'first': 0.61; 'provide': 0.62; 'ever': 0.63; 'grab': 0.64; 'floor,': 0.65; 'receive': 0.71; 'subject:this': 0.84; '"i".': 0.84; '"j"': 0.84; 'off,': 0.84; 'dennis': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: pls help me with this prog Date: Fri, 19 Oct 2012 17:40:26 -0400 Organization: > Bestiaria Support Staff < References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-76-249-17-7.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 103 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350682847 news.xs4all.nl 6969 [2001:888:2000:d::a6]:41381 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31772 On Fri, 19 Oct 2012 10:40:40 +0200, inshu chauhan declaimed the following in gmane.comp.python.general: > in this prog I have written a code to calculate teh centre of a given 3D data.. > One: you didn't supply a sample of the data, so none of us can even attempt to run the code. > but i want to calculate it for every 3 points not the whole data, but > instead of giving me centre for every 3 data the prog is printing the > centre 3 times... > What do you mean by the center [American spelling ]? After all, to define a volume in 3D space you need a minimum of FOUR points (of three [Cartesian] coordinates: x, y, z). Using only three points nets you only a /plane/. > import cv > from math import floor, sqrt, ceil > from numpy import array, dot, subtract, add, linalg as lin > > > > > def CalcCentre(data): > centre = array([0,0,0]) > count = 0 > n = 0 > for p in data[n:n+3]: > centre = add(centre, array(p[:3])) > count += 1 > centre = dot(1./count, centre) > return centre > n += 1 > def ReadPointCloud(filename): > f = open(filename) > result = [] > for l in f: > sp = l.split() > t = tuple(map(float, sp[1:4])) > result.append(t) > return result > > def main (data): > > > j = 0 > for i in data[:3]: > while j != 3: > centre = CalcCentre(data) > j += 1 > print centre Huh... First off, you are looping over the first three elements of data, extracting each as "i". THEN you totally ignore "i" and do a while loop of "j" from 0..2, each time passing ALL of "data" to the calculation routine. When "j" reaches 3, you break out of the while loop, and grab the next element of "data" into "i" -- since "j" is still three, you then skip the whole while loop and get another element of "data"... and skip the while loop again. I suspect what you want here, presuming "data" has the form: [ [x,y,z], [x,y,z], [x,y,z], ... ] for point in data: center = CalcCentre(point) print center OR, if CalcCentre is supposed to receive three points as input... and you want to process every three contiguous points.. for i in range(len(data)-2): center = CalcCentre(data[i:i+2]) print center > > > if __name__ == '__main__': > data = ReadPointCloud(r'Z:\data\NEHreflectance_Scanner 1_part.txt') > > main(data) This should be indented the same as the previous line. It doesn't affect running stand-alone, but if you ever try to import this script it will attempt to execute main() but will have no data to process, and give you a trace-back. This would be much easier to diagnose if you provide a sample of the input data, and a sample of what you EXPECT to see for that data. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/