Mailing List Archive

where is the error?
Hello,

I'm trying to assign data into an array with the nonzero function.
There is my code.

from numarray import *
diff_temp=(logical_and(values[:,5] > -2,values[:,5] < 2)).nonzero()

This command works fine but when I apply the following,

values_matchup=values_Stumpf[diff_temp_Stumpf,:]

I have this error message:
IndexError: each subindex must be either a slice, an integer,
Ellipsis, or NewAxis

Does someone know what it is the problem? I'm using python2.4.3 on
Ubuntu.

Using this command with python on windows xp worked fine.

Thank you for the help,
Cedric
--
http://mail.python.org/mailman/listinfo/python-list
Re: where is the error? [ In reply to ]
lajam@caramail.com wrote:
> Hello,
>
> I'm trying to assign data into an array with the nonzero function.
> There is my code.
>
> from numarray import *
> diff_temp=(logical_and(values[:,5] > -2,values[:,5] < 2)).nonzero()
>

Does that have something to do with the question below?

> This command works fine but when I apply the following,
>
> values_matchup=values_Stumpf[diff_temp_Stumpf,:]
>

Clearly, from the error message, the index diff_temp_Stumpf is not one
of the allowed types. Have you examined its value? Printed it? Set
it equal to a known legal value and tried that line again?

First thing: Find out what value that index has, then if it's necessary
to ask your question again, include that information and we'll have
something to go on in forming an answer.

Gary Herron

> I have this error message:
> IndexError: each subindex must be either a slice, an integer,
> Ellipsis, or NewAxis
>
> Does someone know what it is the problem? I'm using python2.4.3 on
> Ubuntu.
>
> Using this command with python on windows xp worked fine.
>
> Thank you for the help,
> Cedric
> --
> http://mail.python.org/mailman/listinfo/python-list
>

--
http://mail.python.org/mailman/listinfo/python-list
Re: where is the error? [ In reply to ]
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:

values_matchup=values_Stumpf[diff_temp_Stumpf,:]

But it didn't work. I'm sure that there is a specific reason. 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. 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.

Thanks for the help,
Cedric












--
http://mail.python.org/mailman/listinfo/python-list
Re: where is the error? [ In reply to ]
On Jun 27, 7:54 pm, la...@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?
--
http://mail.python.org/mailman/listinfo/python-list
Re: where is the error? [ In reply to ]
There was an error with the name of the variable !!!! I would not ask
this if it was just a question of different variable names !!!!!

diff_temp=(logical_and(values[:,5] > -2,values[:,5] < 2)).nonzero()
new_values=values[diff_temp,:]

Okay, I'm going to try to explain that more specifically that I did. I
have an array called values (size mxn). In this database, I just want
the lines for which the values of the nth row are between two values
(it's the purpose of diff_temp). So diff_temp gets me the number of
the lines for which this latter criteria is right. But I'm interested
on the values of the lines corresponding to the number given by
diff_temp.


In matlab, I will do

diff_temp=find(values(:,5) > -2 & values[:,5) <2)

new_values=values(diff_temp,:)

Is it clear?

Thanks
Cedric
--
http://mail.python.org/mailman/listinfo/python-list
Re: where is the error? [ In reply to ]
On Jun 27, 10:12 pm, la...@caramail.com wrote:
> There was an error with the name of the variable !!!! I would not ask
> this if it was just a question of different variable names !!!!!
>

Calm down. Stop shouting. It is not evident whether the above means
that diff_temp_Stumpf was an error (should have been merely diff_temp)
or not.

> diff_temp=(logical_and(values[:,5] > -2,values[:,5] < 2)).nonzero()
> new_values=values[diff_temp,:]
>
> Okay, I'm going to try to explain that more specifically that I did. I
> have an array called values (size mxn). In this database, I just want
> the lines for which the values of the nth row are between two values
> (it's the purpose of diff_temp). So diff_temp gets me the number of
> the lines for which this latter criteria is right.

I think that you mean that diff_temp will be an array of the numberS
(plural) of the lines (rows?) in values array that met the -2 < x < 2
criterion. Now you want to be able to use diff_temp to get the
corresponding subset of some other array. Am I getting close?

>
But I'm interested
> on the values of the lines corresponding to the number given by
> diff_temp.

Now you want to be able to use diff_temp to get the corresponding
subset of some other array. Am I getting close?

Perhaps you need something like other_array.take(diff_temp) ?

>
> In matlab, I will do
>
> diff_temp=find(values(:,5) > -2 & values[:,5) <2)
>
> new_values=values(diff_temp,:)
>
> Is it clear?

Not very, I don't grok matlab.

By the way, shouldn't you be using numpy? I thought numarray was going
away by mid-2008 i.e. now.

HTH,
John





> Thanks
> Cedric

--
http://mail.python.org/mailman/listinfo/python-list
Re: where is the error? [ In reply to ]
>
> I think that you mean that diff_temp will be an array of the numberS
> (plural) of the lines (rows?) in values array that met the -2 < x < 2
> criterion. Now you want to be able to use diff_temp to get the
> corresponding subset of some other array. Am I getting close?


I think that you're getting close. I want to get the lines that met
the criterion. Diff_temp is an array containing the values of the
lines. So bascially,



> Now you want to be able to use diff_temp to get the corresponding
> subset of some other array. Am I getting close?

yes


> Perhaps you need something like other_array.take(diff_temp) ?


And my problem was that the commands worked on windows but not on
linux.


> By the way, shouldn't you be using numpy? I thought numarray was going
> away by mid-2008 i.e. now.

I know, but i'm not sure that it's the problem.

Thanks
Cedric
--
http://mail.python.org/mailman/listinfo/python-list
Re: where is the error? [ In reply to ]
>
> I think that you mean that diff_temp will be an array of the numberS
> (plural) of the lines (rows?) in values array that met the -2 < x < 2
> criterion. Now you want to be able to use diff_temp to get the
> corresponding subset of some other array. Am I getting close?


I think that you're getting close. I want to get the lines that met
the criterion. Diff_temp is an array containing the values of the
lines. So bascially,



> Now you want to be able to use diff_temp to get the corresponding
> subset of some other array. Am I getting close?

yes


> Perhaps you need something like other_array.take(diff_temp) ?


And my problem was that the commands worked on windows but not on
linux.


> By the way, shouldn't you be using numpy? I thought numarray was going
> away by mid-2008 i.e. now.

I know, but i'm not sure that it's the problem.

Thanks
Cedric
--
http://mail.python.org/mailman/listinfo/python-list
Re: where is the error? [ In reply to ]
>
> I think that you mean that diff_temp will be an array of the numberS
> (plural) of the lines (rows?) in values array that met the -2 < x < 2
> criterion. Now you want to be able to use diff_temp to get the
> corresponding subset of some other array. Am I getting close?


I think that you're getting close. I want to get the lines that met
the criterion. Diff_temp is an array containing the values of the
lines. So bascially,



> Now you want to be able to use diff_temp to get the corresponding
> subset of some other array. Am I getting close?

yes


> Perhaps you need something like other_array.take(diff_temp) ?


And my problem was that the commands worked on windows but not on
linux.


> By the way, shouldn't you be using numpy? I thought numarray was going
> away by mid-2008 i.e. now.

I know, but i'm not sure that it's the problem.

Thanks
Cedric
--
http://mail.python.org/mailman/listinfo/python-list
Re: where is the error? [ In reply to ]
>
> I think that you mean that diff_temp will be an array of the numberS
> (plural) of the lines (rows?) in values array that met the -2 < x < 2
> criterion. Now you want to be able to use diff_temp to get the
> corresponding subset of some other array. Am I getting close?


I think that you're getting close. I want to get the lines that met
the criterion. Diff_temp is an array containing the values of the
lines. So bascially,



> Now you want to be able to use diff_temp to get the corresponding
> subset of some other array. Am I getting close?

yes


> Perhaps you need something like other_array.take(diff_temp) ?


And my problem was that the commands worked on windows but not on
linux.


> By the way, shouldn't you be using numpy? I thought numarray was going
> away by mid-2008 i.e. now.

I know, but i'm not sure that it's the problem.

Thanks
Cedric
--
http://mail.python.org/mailman/listinfo/python-list
Re: where is the error? [ In reply to ]
>
> I think that you mean that diff_temp will be an array of the numberS
> (plural) of the lines (rows?) in values array that met the -2 < x < 2
> criterion. Now you want to be able to use diff_temp to get the
> corresponding subset of some other array. Am I getting close?


I think that you're getting close. I want to get the lines that met
the criterion. Diff_temp is an array containing the values of the
lines. So bascially,



> Now you want to be able to use diff_temp to get the corresponding
> subset of some other array. Am I getting close?

yes


> Perhaps you need something like other_array.take(diff_temp) ?


And my problem was that the commands worked on windows but not on
linux.


> By the way, shouldn't you be using numpy? I thought numarray was going
> away by mid-2008 i.e. now.

I know, but i'm not sure that it's the problem.

Thanks
Cedric
--
http://mail.python.org/mailman/listinfo/python-list
Re: where is the error? [ In reply to ]
lajam@caramail.com wrote:
> ... And my problem was that the commands worked on windows but not on
> linux.
>
>> By the way, shouldn't you be using numpy? I thought numarray was going
>> away by mid-2008 i.e. now.
> I know, but i'm not sure that it's the problem.

It's your job to get certain of some things, and what people are
proposing are experiments you can do to find the answer. The problem
is yours, the benefit of having the code work will be yours, and
you, unlike us, are in a position to perform experiments.

Don't be as vague as "the commands worked on windows but not on linux."
That kind of statement is usually a flag that you _think_ you typed the
same thing. Write a complete, small test program that demonstrates your
success on XP. Move the program to Ubuntu (remembering about line
endings) via flash drive or something. Run _exactly_ the same program
on Ubuntu. If you get a failure, keep trimming the program on Ubuntu
til you find the smallest program that breaks. Take it back to XP and
make sure it still runs there.

Don't give partial version information. I know you have two systems:
Ubuntu (who knows what version), python 2.4.3, numarray who knows.

The Windows box is running XP, but what service pack? what version of
Python on XP? What version of numarray on XP? In collecting all of
this information _before_ you ask, you often discover the answer to
your question without needing to ask anyone else.

If numpy might solve your problem, why avoid trying it simply because
it might not do so?

Sorry, this a long form of "read smart questions," but it did include
some suggestions about how you could find the problem in your particular
case.

--Scott David Daniels
Scott.Daniels@Acm.Org
--
http://mail.python.org/mailman/listinfo/python-list
Re: Where is the error? [ In reply to ]
On 07Aug2023 08:02, Barry <barry@barrys-emacs.org> wrote:
>> On 7 Aug 2023, at 05:28, Cameron Simpson via Python-list <python-list@python.org> wrote:
>> Used to use a Pascal compiler once which was uncannily good at
>> suggesting where you'd missing a semicolon.
>
>Was that on DEC VMS? It was a goal at DEC for its compilers to do this well.

No, a PDP-11 using V7 UNIX.

>They could output the errors in a machine readable format to allow editors to auto fix.
>I am learning rust and it is very good at suggesting fixes.
>There is a command to apply fixes automatically, cargo fix.

Neat.

Cheers,
Cameron Simpson <cs@cskk.id.au>
--
https://mail.python.org/mailman/listinfo/python-list