Re: [Numpy-discussion] Scalars, comparisons and indexing. Is this a bug?

2006-07-14 Thread Bill Baxter
I believe that's the problem that the indexing PEP from Travis is
supposed to address:
  http://www.python.org/dev/peps/pep-0357/
So I think there's not much anyone can do about it untill the PEP is
accepted and implemented.

Maybe you can cast to int?
 In [34]: (1,2)[int(a[0]==b)]


--bb

On 7/15/06, Fernando Perez [EMAIL PROTECTED] wrote:
 Hi all,

 I just got bit by this problem, and I'm not really sure if this is
 something that should be considered a numpy bug or not.  It is a bit
 unpleasant, at the least, though it can be easily worked around.
 Here's a simple demonstration:

 In [32]: a=array([1,2])

 In [33]: b=1

 In [34]: (1,2)[a[0]==b]
 ---
 exceptions.TypeError Traceback (most
 recent call last)

 /home/fperez/research/code/mwmerge/mwadap-merge/mwadap/test/ipython console

 TypeError: tuple indices must be integers


 Whereas this works:

 In [35]: c=2

 In [36]: (1,2)[c==b]
 Out[36]: 1

 Basically, it seems that array scalars, upon comparisons, return
 something that doesn't 'looke enough like an int' to python for it to
 let you use it as an index, it's a 'boolscalar':

 In [38]: a0==b0
 Out[38]: True

 In [39]: type _
 --- type(_)
 Out[39]: type 'boolscalar'


 Advice? Is this a numpy bug?  Or should it just be left alone, and
 this kind of inconvenience will disappear when 2.5 is out, with
 __index__ support?

 Cheers,

 f


 -
 Using Tomcat but need to do more? Need to support web services, security?
 Get stuff done quickly with pre-integrated technology to make your job easier
 Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
 http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
 ___
 Numpy-discussion mailing list
 Numpy-discussion@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/numpy-discussion



-- 
William V. Baxter III
OLM Digital
Kono Dens Building Rm 302
1-8-8 Wakabayashi Setagaya-ku
Tokyo, Japan  154-0023
+81 (3) 3422-3380


-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
___
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion


Re: [Numpy-discussion] Scalars, comparisons and indexing. Is this a bug?

2006-07-14 Thread Fernando Perez
On 7/14/06, Bill Baxter [EMAIL PROTECTED] wrote:
 I believe that's the problem that the indexing PEP from Travis is
 supposed to address:
   http://www.python.org/dev/peps/pep-0357/
 So I think there's not much anyone can do about it untill the PEP is
 accepted and implemented.

 Maybe you can cast to int?
  In [34]: (1,2)[int(a[0]==b)]

Yup, that's the workaround I'm using.

I was just wondering if comparisons between array scalars shouldn't
return /true/ booleans (which can be used as indices) instead of array
scalar booleans.  I realize that the __index__ support in 2.5 will
make this point moot (the PEP you point to), but perhaps this
particular one can actually be fixed today, for all users of python
pre-2.5.  However, I haven't really wrapped my head enough around all
the subtleties of array scalars to know whether 'fixing' this
particular problem will introduce other, worse ones.

Cheers,

f


-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
___
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion