where is the error?

John Machin sjmachin at lexicon.net
Fri Jun 27 07:11:50 EDT 2008


On Jun 27, 7:54 pm, la... at caramail.com wrote:
> Maybe I didn't explain correctly what i wanted to do. I have a
> database and I just want to pick data under a certain criteria. So I
> wanted to use a function like nonzero or find or where to find the
> line for corresponding to the data following this criteria. So to find
> the lines, I used nonzero and it corresponds to the command:
>
> diff_temp=(logical_and(values[:,5] > -2,values[:,5] < 2)).nonzero()
>
> so YES it has SOMETHING to do with the question below.
>
> diff_temp=(array([  0,   6,   7,  10,  14,  15,  16,  17,  21,  22,
> 24,  25,  26,
>         27,  31,  32,  33,  36,  37,  38,  39,  40,  41,  42,  46,
> 47,
>         48,  49,  50,  51,  52,  53,  54,  59,  60,  61,  62,  71,
> 72,
>         73,  74,  75,  80,  81,  82,  83,  84,  85,  86,  87,  88,
> 89,
>         90,  91,  92,  93,  94,  95,  96,  97,  98,  99, 100, 101,
> 102,
>        103, 104, 105, 106, 107, 111, 112, 113, 114, 115, 116]),)
>
> So now I just want to have the data corresponding to those lines.
> Thinking that python was a powerful tool, I thought that it was just
> possible to assign those line directly in a matrix. So I used the
> command:

You will need to explain what you mean by "assign those line directly
in a matrix". We are not mind-readers, and neither is Python.

>
> values_matchup=values_Stumpf[diff_temp_Stumpf,:]
>
> But it didn't work. I'm sure that there is a specific reason.

The specific reason is as Gary explained. What you have done is assign
the name diff_temp to some expression. This has absolutely nothing to
do with diff_temp_Stumpf which is an utterly different name, and as
far as we can tell has no referent as all, hence the error message
that you got.

You may need one of the following solutions:
(1)
    diff_temp_Stumpf = diff_temp
(2)
    def make_diff_temp_thing(values):
        return (logical_and(v[:,5] > -2,v[:,5] < 2)).nonzero()
    # much later ...
    values_matchup = make_temp_thing(values_Stumpf)
but it's rather hard to understand what you want ...

> But my
> concern was that this command works FINE if I use python on windows xp
> but doesn't work if I use python on my linux Ubuntu machine.

The usual cause of this kind of phenomenon is experimental error e.g.
you didn't execute exactly the same statements (not "commands") on
Windows as on Linux.

> So I
> wondered what was wrong and if there is a easy and simple way to get
> directly a new array with the data corresponding to a certain
> criteria.

It might help if you use less abstract phrases than "corresponding to
a certain criteria". Can you relate how you would solve this problem
in a computer language other that Python?



More information about the Python-list mailing list