Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31839

Re: pls help me with this prog

Newsgroups comp.lang.python
Date 2012-10-21 01:09 -0700
References <mailman.2495.1350636042.27098.python-list@python.org>
Subject Re: pls help me with this prog
From 88888 Dihedral <dihedral88888@googlemail.com>
Message-ID <mailman.2580.1350806993.27098.python-list@python.org> (permalink)

Show all headers | View raw


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)


Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

pls help me with this prog inshu chauhan <insideshoes@gmail.com> - 2012-10-19 10:40 +0200
  Re: pls help me with this prog rusi <rustompmody@gmail.com> - 2012-10-19 06:06 -0700
  Re: pls help me with this prog Tim Roberts <timr@probo.com> - 2012-10-20 19:33 -0700
  Re: pls help me with this prog 88888 Dihedral <dihedral88888@googlemail.com> - 2012-10-21 01:09 -0700
  Re: pls help me with this prog 88888 Dihedral <dihedral88888@googlemail.com> - 2012-10-21 01:09 -0700

csiph-web