Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: error

31 views
Skip to first unread message

Dave Angel

unread,
Nov 6, 2012, 8:05:50 AM11/6/12
to inshu chauhan, pytho...@python.org
On 11/06/2012 07:31 AM, inshu chauhan wrote:
> I am getting this error while running my programme.. :
>
> error: index is out of range

Please paste the whole error, including the traceback. It'll show you
the line that had the error, as well as the calling sequence that got
you there.

>
> I cannot find a valid reason for it in my prog can somebody suggest what
> may be possible reasons for this error..
>
> The part of the code is :
>
> def addpoints (data, points, ix, iy): # makes a list of relevant points
> if 0 < ix < data.width and 0 < iy < data.height:
> point = data[ix, iy]

Tell us the type of the parameters. Perhaps data is of type Zanzibar,
and the first subscript is the height, and the second is the width?
Show us your class definition, since data is obviously not a built-in
collection.

> if point != (0.0, 0.0, 0.0):
> points.append(point)
> return points
>
> for dx in xrange(-mask_size2, mask_size2 + 1):
> for dy in xrange(-mask_size2, mask_size2 + 1):

What is the meaning and value of mask_size2 ? Is it a negative int?

> ix, iy = x + dx, y + dy
> addpoints(data, points, ix , iy )
>
>

BTW, this function's initial comment is incorrect. It doesn't make a
list, it appends to one passed in. And there's no point in returning
that list, since it has already been modified. By good convention, a
simple function either returns a result or modifies its parameter, it
shouldn't do both. Obviously there are exceptions for complex
functions, but even then, for a single collection, it should either be
modified in place, or created and returned, not both.

--

DaveA

woooee

unread,
Nov 6, 2012, 2:59:50 PM11/6/12
to
From this line, "data" appears to be a class
if 0 < ix < data.width and 0 < iy < data.height:
From this line, "data" appears to be a list, although a two
dimensional list would be accessed as data[ix][iy]
        point = data[ix, iy]

Also, returning a list from a function is a matter of preference.
Some people argue that it should be returned to make it obvious. If
you do not know the difference between what is mutable and what is not
mutable, then return everything until you do.

Dave Angel

unread,
Nov 8, 2012, 11:33:53 AM11/8/12
to inshu chauhan, pytho...@python.org, woooee
On 11/08/2012 08:47 AM, inshu chauhan wrote:
> Actually data is neither a zanzibar nor a class nor a list.. its a yml
> image. with pixels
> I am trying to access pixels of a 3D image through this programme..
>


You want us to keep guessing? And without supplying any new
information? There's no such thing as a yml image in Python, though
there might be some library that supports such a thing with some class
structure. And you just might have downloaded it from the
http://www.ymlgroup.com/obscurehiddenlocation/downloads site, and
imported it using from notzanzibar import DataType.

Then you'd have instantiated it in some code like
data = DataType(filename)

and then the type of data would be notzanzibar.DataType and the docs
would be probably available somewhere on www.invalid.com/docs

The only new guess:

A 3D image would presumably have 3 subscripts, and you're only supplying
two.



If you want help, be explicit:

1) what version of CPython are you using, and on what OS?
2) what web site did you download some extra library from ?
3) what import statement did you use ?
4) How are all those global variables initialized ?
5) What command did you use to start the script ? Did you run it from
command.com, or from some IDE ?
5) Exactly what error message did you get, including the traceback ?
6) What have you done to try to figure out your own error?




--

DaveA

Jerry Hill

unread,
Nov 8, 2012, 11:41:22 AM11/8/12
to inshu chauhan, pytho...@python.org
On Thu, Nov 8, 2012 at 8:47 AM, inshu chauhan <insid...@gmail.com> wrote:
> Actually data is neither a zanzibar nor a class nor a list.. its a yml
> image. with pixels
> I am trying to access pixels of a 3D image through this programme..

When you're having trouble debugging a program, and decide to turn to
a mailing list for help, it can be hard to know what information
people are going to need to help you. The easiest way to know that
people have enough information to help debug your program is to
provide a short, self contained, example of your code that
demonstrates the problem that you're having.

See http://sscce.org/ for more on why it's helpful, and how to turn a
long program into sample code that will let us help you.

--
Jerry

Dave Angel

unread,
Nov 12, 2012, 10:04:08 AM11/12/12
to inshu chauhan, pytho...@python.org, woooee
On 11/09/2012 09:08 AM, inshu chauhan wrote:
> Actually this one.. and its the last..
>
> <snip>
>>>>>
>>>>
>>>> The only extra libary i am using is Opencv , downloaded from
>>>> http://sourceforge.net/projects/opencvlibrary/
>>>>
>>>>

and numpy.

>>>>
>>>>> 3) what import statement did you use ?
>>>>>
>>>>
>>>> import cv
>>>>
<snip>
>>>>
>>>>> 5) Exactly what error message did you get, including the traceback ?
>>>>>
>>>>
>>>> Traceback (most recent call last):
>>>> File "Z:\modules\Masking_an_image_dynamically.py", line 155, in
>>>> <module>
>>>> AccessPixels(data)
>>>> File "Z:\modules\.py", line 147, in AccessPixels
>>>> CreateMask(data, x, y)
>>>> File "Z:\modules\new_classification.py", line 110, in CreateMask
>>>> point = data[iy, ix ]
>>>>
>>>> error: index is out of range
>>>>
>>>> The line numbers here and the file attached may be different because I
>>>> have removed a lot of print statements which I was using to debug the
>>>> error..
>>>>

More than that is wrong. The file names are different. If I guess from
your source file that all this code is in your own script,
"Masking_an_image_dynamically.py" then two of the filenames in the
traceback indicate big problems.

Further, on the same assumption, the function CreateMask has no such
line as 'point = data[iy, ix]

I did spend some time with the website
http://sourceforge.net/projects/opencvlibrary/

but all I see is C++ docs, and since it's enormous, I didn't think I'm
likely to find out anything directly from there. The particular thing I
was looking for was whether rows or columns are specified first when
treating 'data" as a list of lists. In other words, I look at the two
lines:

CreateMask(data, x, y)
and
point = data[iy, ix]

and try to figure out which one is unreasonable. Find out the
convention used in the module, and stay consistent with it. In
Photoshop. an 8x10 is a portrait layout, while 10x8 is landscape. In
other words, row number is first. But i have no idea what Opencv uses.

Since I've not used either Opencv nor numpy, somebody else had better
jump in after you post the traceback that matches your source file.
Perhaps it's IDLE that's getting confused. Have you tried running it
from a cmd.exe prompt, and pasting from that cmd window into a message?



--

DaveA
0 new messages