[EMAIL PROTECTED] wrote:
Thats right. I wanted c1 and c2 to retrieve the values returned by t1
and t2 . Values for t1 and t2 could be anything. Also tbl is global.
Then you need to return t1 and t2 in test, e.g.:
py> import numarray as na
py> tbl = na.zeros((32, 16))
py> def test():
... t1 = 0x
Thats right. I wanted c1 and c2 to retrieve the values returned by t1
and t2 . Values for t1 and t2 could be anything. Also tbl is global.
-SB
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
Steven Bethard wrote:
py> import numarray as na
py> tbl = na.zeros((32, 16))
py> def get_value():
... data = test()
... c1 = data[0]
... c2 = data[1]
... print tbl[c1, c2]
...
py> def test():
... t1 = 0x0
... t2 = 0x1
... return tbl[t1, t2]
...
p
Steven Bethard wrote:
> [EMAIL PROTECTED] wrote:
> > from Numeric import *
> >
> > # Initialize the 32x16 global array to zeros
> > tbl = zeros((32, 16)
> >
> > def getValue( value):
> > data = test(value)
> > c1 = data[0]
> > c2 = data[1]
> > print tbl[c1, c2]
> >
> > def test( va
Hello,
I am getting the following error when returning a list:
return tbl[c1,c2]
"IndexError: each subindex must be either a slice, an integer,
Ellipsis, or NewAxis"
What does it mean?
Here's the code snippet
from Numeric import *
# Initialize the 32x16 global array to zeros
tbl = zeros(
[EMAIL PROTECTED] wrote:
from Numeric import *
# Initialize the 32x16 global array to zeros
tbl = zeros((32, 16)
def getValue( value):
data = test(value)
c1 = data[0]
c2 = data[1]
print tbl[c1, c2]
def test( value):
t1 = 0x0
t2 = 0x1
return tbl[t1, t2]
In test, tbl[0x0,
Scott David Daniels <[EMAIL PROTECTED]> wrote:
> Ishwor wrote:
> > On Thu, 23 Dec 2004 13:57:55 -0300, Batista, Facundo
> > <[EMAIL PROTECTED]> wrote:
> >>#- True, true. Maybe you could lobby for copy as a builtin in
> >>#- Python 3000?
> >>
> >>That's a good idea to me. But copy() as a builtin
Ishwor wrote:
On Thu, 23 Dec 2004 13:57:55 -0300, Batista, Facundo
<[EMAIL PROTECTED]> wrote:
#- True, true. Maybe you could lobby for copy as a builtin in
#- Python 3000?
That's a good idea to me. But copy() as a builtin is not clear if it's
shallow or deep.
IMHO its preferable to use shallow
Grant Edwards wrote:
On 2004-12-23, Steven Bethard <[EMAIL PROTECTED]> wrote:
Ah, my mistake, I missed the [:] after the source argument
that was taking a copy... which brings up the question, how
many other people would miss it?
Too many. This is why I greatly prefer
list(lst)
T
Grant Edwards wrote:
I would have guessed that calling list() on a list
was a noop. I would be wrong. Surprised, but wrong.
I guess it's probably worth pointing out that most builtin mutable types
can be copied using the type constructor:
py> def check(obj):
... copy = type(obj)(obj)
...
On Thu, 23 Dec 2004 13:57:55 -0300, Batista, Facundo
<[EMAIL PROTECTED]> wrote:
>
>
> [Steven Bethard]
>
> #- True, true. Maybe you could lobby for copy as a builtin in
> #- Python 3000?
>
> That's a good idea to me. But copy() as a builtin is not clear if it's
> shallow or deep.
IMHO its
Title: RE: list IndexError
[Steven Bethard]
#- True, true. Maybe you could lobby for copy as a builtin in
#- Python 3000?
That's a good idea to me. But copy() as a builtin is not clear if it's shallow or deep.
.
Grant Edwards wrote:
Wouldn't the clearest way to get a copy would be to do
something like:
copy(lst) # I still think copy.copy() is a bit verbose...
True, true. Maybe you could lobby for copy as a builtin in Python 3000?
Steve
--
http://mail.python.org/mailman/listinfo/python-list
On 2004-12-23, Steven Bethard <[EMAIL PROTECTED]> wrote:
>> Ah, my mistake, I missed the [:] after the source argument
>> that was taking a copy... which brings up the question, how
>> many other people would miss it?
>
> Too many. This is why I greatly prefer
>
> list(lst)
To me, that's jus
Mike C. Fletcher wrote:
Ah, my mistake, I missed the [:] after the source argument that was
taking a copy... which brings up the question, how many other people
would miss it?
Too many. This is why I greatly prefer
list(lst)
to
lst[:]
It's also clearer to me. Do I really want a "slice" of
M.E.Farmer wrote:
Hello Ishwor ,
The simpliest way I can explain slicing is that the slices point to the
spot *between* the items..
Take this list for example
slicer = [0,1,2,3,4,5]
slicer [1]
1
slicer [1:2]
[1]
slicer [:-1]
[0,1,2,3,4]
slicer[2,4]
[2,3]
You can also use a "stride" rather t
Steven Bethard wrote:
Ishwor wrote:
i am trying to remove an item 'e' from the list l
I thought it might be helpful to code some of the alternatives you've
been given and look at the timings to put things into perspective.
Corrected timings[1] using:
$ python -m timeit -s "import remove" "remove.
Fredrik Lundh wrote:
Mike C. Fletcher wrote:
yeah actually i saw what Fedrik had to say above. I created a sliced
copy of the l & did my homework within the for loop
You might want to check it again before you hand it in ;) ...
...
that's not the code he quoted in the mail you replie
Peter Otten wrote:
I do not think it measures what you think it measures.
Ah, good point. . . so we were actually measuring how long it takes to make zero
replacements on the modified list, which explains the downward trend of the
timings (as the modified list gets shorter).
Adding the list copy
Steven Bethard wrote:
Ishwor wrote:
i am trying to remove an item 'e' from the list l
I thought it might be helpful to code some of the alternatives you've
been given and look at the timings to put things into perspective. The
code:
remove.py
def remov
Steven Bethard wrote:
> I thought it might be helpful to code some of the alternatives you've
> been given and look at the timings to put things into perspective. The
> code:
>
> remove.py
> def remove_lc(x, lst):
> lst[:] = [item for item in lst if
On Thu, 23 Dec 2004 08:35:57 +0100, Fredrik Lundh
<[EMAIL PROTECTED]> wrote:
> Mike C. Fletcher wrote:
>
> >>yeah actually i saw what Fedrik had to say above. I created a sliced
> >>copy of the l & did my homework within the for loop
> >>
> > You might want to check it again before you hand it in
Mike C. Fletcher wrote:
>>yeah actually i saw what Fedrik had to say above. I created a sliced
>>copy of the l & did my homework within the for loop
>>
> You might want to check it again before you hand it in ;) ...
>
> >>> def ishwor( source ):
> ... for item in source:
> ... if item
Ishwor wrote:
...
I believe lamda's are unnamed functions aren't they?? Still learning... ;-)
Yes.
yeah actually i saw what Fedrik had to say above. I created a sliced
copy of the l & did my homework within the for loop
You might want to check it again before you hand it in ;) ...
>>> def ish
Hello Ishwor ,
The simpliest way I can explain slicing is that the slices point to the
spot *between* the items..
Take this list for example
slicer = [0,1,2,3,4,5]
>>> slicer [1]
1
>>> slicer [1:2]
[1]
>>> slicer [:-1]
[0,1,2,3,4]
>>> slicer[2,4]
[2,3]
Hth,
M.E.Farmer
--
http://mail.pyth
On Wed, 22 Dec 2004 21:42:16 GMT, Steven Bethard
<[EMAIL PROTECTED]> wrote:
> Ishwor wrote:
> > i am trying to remove an item 'e' from the list l
>
> I thought it might be helpful to code some of the alternatives you've
> been given and look at the timings to put things into perspective. The
> co
Ishwor wrote:
i am trying to remove an item 'e' from the list l
I thought it might be helpful to code some of the alternatives you've
been given and look at the timings to put things into perspective. The
code:
remove.py
def remove_lc(x, lst):
lst[:
On Thu, 23 Dec 2004 07:27:52 +1000, Egor Bolonev <[EMAIL PROTECTED]> wrote:
> On Thu, 23 Dec 2004 06:56:02 +1030, Ishwor <[EMAIL PROTECTED]> wrote:
>
> l
> > ['a', 'b', 'c', 'd', 'e']
> for x in l[:]:
> >if x == 'd':
> >l.remove('d');
> >
> l
> > ['a', 'b', '
On Thu, 23 Dec 2004 06:56:02 +1030, Ishwor <[EMAIL PROTECTED]> wrote:
l
['a', 'b', 'c', 'd', 'e']
for x in l[:]:
if x == 'd':
l.remove('d');
l
['a', 'b', 'c', 'e']
This code is so clean and looks very healthy. Python will live a
long way because its a cute language.
imho the
On Wed, 22 Dec 2004 14:59:32 -0500, Mike C. Fletcher
<[EMAIL PROTECTED]> wrote:
[snip]
>
> Probably the most pythonic approach to this problem when dealing with
> small lists is this:
>
>result = [ item for item in source if item != 'e' ]
>
> or, if you're using an older version of Python wit
Ishwor wrote:
i am trying to remove an item 'e' from the list l but i keep getting IndexError.
I know the size of the list l is changing in the for loop & its sort
of trivial task but i found no other way than to suppress the
IndexError by doing a pass. any other ways you guys can suggest? Also
is
"Ishwor" <[EMAIL PROTECTED]> wrote:
> i am trying to remove an item 'e' from the list l but i keep getting
> IndexError.
> I know the size of the list l is changing in the for loop & its sort
> of trivial task but i found no other way than to suppress the
> IndexError by doing a pass. any other w
i am trying to remove an item 'e' from the list l but i keep getting IndexError.
I know the size of the list l is changing in the for loop & its sort
of trivial task but i found no other way than to suppress the
IndexError by doing a pass. any other ways you guys can suggest? Also
is this a good or
33 matches
Mail list logo