Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '__name__': 0.07; 'subject:help': 0.07; 'friday,': 0.09; 'teh': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'assume': 0.11; "'__main__':": 0.16; 'add,': 0.16; 'dot,': 0.16; 'numpy': 0.16; 'prog': 0.16; 'wrote:': 0.17; 'math': 0.20; 'written': 0.20; 'import': 0.21; 'cc:2**0': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'points': 0.29; 'code': 0.31; 'print': 0.32; 'received:google.com': 0.34; 'list': 0.35; 'data,': 0.35; 'from:addr:googlemail.com': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'subject:with': 0.36; 'october': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'instead': 0.39; 'help': 0.40; 'skip:y 20': 0.62; 'skip:n 10': 0.63; 'floor,': 0.65; 'subject:this': 0.84; 'received:209.85.213.184': 0.91 Newsgroups: comp.lang.python Date: Sun, 21 Oct 2012 01:09:44 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=123.192.32.215; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 123.192.32.215 MIME-Version: 1.0 Subject: Re: pls help me with this prog From: 88888 Dihedral 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 115 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350806993 news.xs4all.nl 6954 [2001:888:2000:d::a6]:37666 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31839 On Friday, October 19, 2012 4:40:42 PM UTC+8, inshu chauhan wrote: > in this prog I have written a code to calculate teh centre of a given 3D data.. > > > > 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... > > > > 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 > > > > > > if __name__ == '__main__': > > data = ReadPointCloud(r'Z:\data\NEHreflectance_Scanner 1_part.txt') > > > > main(data) > > > > > > > > > > PLS HELP ;;;; # assume data is a list of 3 n numbers, n!=0 n3=data.length() n=n/3 x=sum(data[0:n3:3])/n y=sum(data[1:n3:3])/n z=sum(data[2:n3:3])/n #(x,y,z)