[Numpy-discussion] Accessing rank-0 array value?

Nadav Horesh nadavh at visionsense.com
Mon Jun 7 02:51:07 CDT 2004


b has a scalar properties:

>>> b+3
5

>>> b.rank
0

The odd issue is that rank>0 arrays keeps their type in similar operations:

>>> a = array((2,), type=Int16)
>>> a
array([2], type=Int16)

>>> a + 3
array([5], type=Int16)

I would expect that rank 0 arrays would behave like scalars with a given numarray type (Int8, UInt64, ...).

  Nadav.



-----Original Message-----
From:	Peter Verveer [mailto:verveer at embl-heidelberg.de]
Sent:	Mon 07-Jun-04 12:27
To:	Francesc Alted
Cc:	Numpy Discussion List
Subject:	Re: [Numpy-discussion] Accessing rank-0 array value?
For instance:

 >>> float(b)
2.0

or probably more appropriate since it retains the type:

 >>> b[()]
2

Both not very intuitive, are there any better ways?

On 7 Jun 2004, at 11:17, Francesc Alted wrote:

> Hi,
>
> Perhaps this is a stupid question, but I did not found any easy way to 
> get
> the python object value from a rank-0 numarray array. That is:
>
>>>> from numarray import *
>>>> b=array(2)
>>>> b
> array(2)
>>>> b[0]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> IndexError: Too many indices
>
> In C, that seem to be possible provided you use the call:
> PyObject* PyArray_Return(PyArrayObject *apr)
>
> Is there any way to do that in python?



-------------------------------------------------------
This SF.Net email is sponsored by the new InstallShield X.
>From Windows to Linux, servers to mobile, InstallShield X is the one
installation-authoring solution that does it all. Learn more and
evaluate today! http://www.installshield.com/Dev2Dev/0504
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion







More information about the Numpy-discussion mailing list