[Numpy-discussion] rank-0 arrays ideas
Darren Dale
dd55 at cornell.edu
Fri Feb 18 15:28:23 CST 2005
On Friday 18 February 2005 06:04 pm, Travis Oliphant wrote:
> From the current PEP:
>
>
> Proposed Solution:
>
> The solution proposed by this PEP is to fix the places in Python
> that could use rank-0 arrayobjects to allow for them before raising
> an exception (this will be in the core after-all).
>
> A Python scalar will never be returned unless explicitly
> requested. I think this is the cleanest, easiest to understand
> and code for solution. It may require some explicity conversion
> to int here and there, but it seems like a case of "explicit is
> better than implicit"
>
> Possible compromises:
> - a compromise could be made for OBJECT arrays and
> perhaps LONG arrays if needed.
>
> - a special flag could be defined which is the default
> when an array of integers is constructed and which when
> set rank-0 array returns behave differently.
>
> It is also proposed that slicing, indexing and len() do
> not work (i.e. they raise an error) for rank-0 arrays.
>
>
> Comments:
I have one:
The following script measures the time it takes for in-place array operations,
comparing 0-D arrays with scalars. The results are
0.81 0D double
0.85 0D int
0.11 Scalar float
0.12 Scalar int
Would Numeric3 address this issue?
---
import Numeric as N
import time
a=N.zeros(100000,'d')
one=N.array(1,'d')
d=time.clock()
for i in N.arange(100000):
a[i]+=one
d = time.clock()-d
print d,'0D double'
one=N.array(1)
d=time.clock()
for i in N.arange(100000):
a[i]+=one
d = time.clock()-d
print d,'0D int'
d=time.clock()
for i in N.arange(100000):
a[i]+=1.
d = time.clock()-d
print d,'Scalar float'
d=time.clock()
for i in N.arange(100000):
a[i]+=1
d = time.clock()-d
print d,'Scalar int'
--
Darren
More information about the Numpy-discussion
mailing list