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


Groups > comp.lang.python > #31847

Re: a prob.. error in prog ..dont knw how to correct

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 <z@etiol.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'subsequent': 0.04; 'skip:` 10': 0.05; 'sys': 0.05; '__name__': 0.07; 'data:': 0.07; 'filenames': 0.07; 'nested': 0.07; 'python': 0.09; '"""return': 0.09; 'called.': 0.09; 'lines:': 0.09; 'noted,': 0.09; 'skip:r 60': 0.09; 'def': 0.10; 'subject:error': 0.11; 'useful,': 0.13; "'__main__':": 0.16; '[and': 0.16; 'add,': 0.16; 'assignments': 0.16; 'better:': 0.16; 'dist': 0.16; 'dot,': 0.16; 'hard-code': 0.16; 'iteration': 0.16; 'numpy': 0.16; 'readable': 0.16; 'subject: ..': 0.16; 'throwaway': 0.16; 'wrote:': 0.17; 'previously': 0.18; 'module': 0.19; 'math': 0.20; 'trying': 0.21; 'import': 0.21; 'addition,': 0.21; 'assuming': 0.22; 'terminate': 0.22; 'work.': 0.23; 'statement': 0.23; 'idea': 0.24; 'header:In-Reply-To:1': 0.25; 'skip:[ 10': 0.26; 'values': 0.26; 'functions.': 0.27; 'message- id:@mail.gmail.com': 0.27; 'index,': 0.29; 'loop,': 0.29; 'points': 0.29; 'probably': 0.29; 'this.': 0.29; 'usually': 0.30; 'function': 0.30; 'code': 0.31; 'point': 0.31; 'file': 0.32; 'generally': 0.32; 'print': 0.32; 'problem': 0.33; 'to:addr :python-list': 0.33; 'received:google.com': 0.34; 'or,': 0.34; 'done': 0.34; 'list': 0.35; 'along': 0.35; 'data,': 0.35; 'doing': 0.35; 'sometimes': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'really': 0.36; 'except': 0.36; 'but': 0.36; 'anything': 0.36; 'skip:p 20': 0.36; 'october': 0.37; 'previous': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'little': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'first': 0.61; 'solve': 0.62; 'effective': 0.63; 'times': 0.63; 'making': 0.64; 'floor,': 0.65; 'programs,': 0.71; 'yourself': 0.77; 'subject:.. ': 0.84; 'technique.': 0.84
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:x-originating-ip:in-reply-to:references:from :date:x-google-sender-auth:message-id:subject:to:content-type :x-gm-message-state; bh=mjYlvzAPmChsu4edy2Y7EI9K73WFRxh+NE7H9pX/bqI=; b=CChnx/0JZ3Kf/2nbv/LBn+iv1K3SGlmShlhYh8C8Wp23mvEDIK74RXyMYbp4o2SfGi iiuaOYUsEssRnHu29C0GZoDtyz+prmXIkUHpoqoNFaZKDt2p3IBRnPQ+RxVLJsSjFAbk oC+wQtGPk1wH6tUS/m14ihf1wZjVxYvmuhSwKF213umNOS2TucvIMXDVpXoA6yqn9G3y PDGsiKyZOxgWNn5dxg4G3dPIFYJ4S0k5Sm5fIUpsmgy/s7WEiU5tYQNXgnKvTyzmjkEZ pPdZxpP/rX0s4BoWn0vb2RVxZQoMvxTjZAzNwDbqnL6s+fEfYs/ZDXVNfTUNMJOA5P44 P8LA==
MIME-Version 1.0
Sender z@etiol.net
X-Originating-IP [190.104.31.28]
In-Reply-To <CAFqGZRFHjk3h5ceayEhNboXU3i+wULz01GpJjHv29RXRQ=eM4w@mail.gmail.com>
References <CAFqGZRFHjk3h5ceayEhNboXU3i+wULz01GpJjHv29RXRQ=eM4w@mail.gmail.com>
From Zero Piraeus <schesis@gmail.com>
Date Sun, 21 Oct 2012 07:23:56 -0400
X-Google-Sender-Auth IRza4S45XNQaHHP3ukNGsxXK8EQ
Subject Re: a prob.. error in prog ..dont knw how to correct
To python-list@python.org
Content-Type text/plain; charset=UTF-8
X-Gm-Message-State ALoCoQmnPMKVRjM3bfl2mSexGd/oZedseOmmXYdKzdvs1nsOHsV62NHpi8ODdbymogdTUZkVWKip
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>
Newsgroups comp.lang.python
Message-ID <mailman.2587.1350818660.27098.python-list@python.org> (permalink)
Lines 100
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1350818660 news.xs4all.nl 6906 [2001:888:2000:d::a6]:37954
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31847

Show key headers only | View raw


:

On 21 October 2012 06:09, inshu chauhan <insideshoes@gmail.com> wrote:
> I am new to python and have a little problem to solve ..

> import cv

This module is not used in your code [and isn't part of the standard library].

> from math import floor, sqrt, ceil

You're only using one of these functions.

> from numpy import array, dot, subtract, add, linalg as lin

You're not using any of this.

>     for p in data:
>         x = p[0]
>         y = p[1]
>         z = p[2]

You're repeatedly making assignments in this loop, but because your
subsequent loop is not nested inside it, only the last iteration of x,
y, z will have anything done with them.

>     for i in range(len(data)):

Whenever you find yourself writing

  for i in range(len(seq)):

you're doing something wrong. Instead use something like

  for a, b, c in seq:

or, if you really need the index,

  for i, (a, b, c) in enumerate(seq):

>       dist = sqrt((x[i]-x[i+1])**2 + (y[i]-y[i+1])**2 +(z[i]-z[i+1]**2))

As previously noted, you're going to be repeatedly working with the
last values of x, y and z from the previous loop here. In addition,
since x, y and z are, according to your traceback, floats, trying to
access their members as though they are sequences isn't going to work.

>       return dist

This return statement is inside a loop, and will terminate the
function the first time it's called. That might not be what you want.

> def ReadPointCloud(filename):
>     return [tuple(map(float, l.split()[1:4])) for l in open(filename)]

Assuming your file is along these lines:

  p1 1.23 4.56 7.89
  p2 9.87 6.54 3.21

... ReadPointCloud() ought to work. However, it's not very readable -
map() is sometimes useful, but usually a list comprehension is
clearer. This is better:

def ReadPointCloud(filename):
    """Return a list of 3-tuples from ``filename``."""
    # not tested:
    points = []
    with open(filename) as f:
        for line in f:
            point = tuple(float(x) for x in l.split()[1:4])
            points.append(point)
    return points

> def main (data):
>
>     for i in range(len(data)): # Finding Neighbours
>        for j in range(len(data)):
>           dist = calcdist(data)
>           print dist

This will call calcdist() on everything in data, N**2 times [where N
is the number of points you're working with]. That's probably not what
you want.

> if __name__ == '__main__':
>     data = ReadPointCloud(r'C:\Thesis\NEHreflectance_Scanner_1_part.txt')

Except for throwaway programs, it's not a good idea to hard-code
filenames like this. Better:

if __name__ == '__main__':
    import sys
    data = ReadPointCloud(sys.argv[1])

In summary: copy-pasting code you don't understand and mashing it
together randomly is not generally considered an effective development
technique.

 -[]z.

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


Thread

Re: a prob.. error in prog ..dont knw how to correct Zero Piraeus <schesis@gmail.com> - 2012-10-21 07:23 -0400

csiph-web