[Numpy-discussion] Response to PEP suggestions

Duncan Child duncan at enthought.com
Fri Feb 18 08:50:19 EST 2005

konrad.hinsen at laposte.net wrote:

> On Feb 17, 2005, at 23:22, Duncan Child wrote:
>> I have attached some code that illustrates part of the pain we have 
>> experienced developing libraries of algorithms that can handle both 
>> arrays and scalars. The attached library is the reusable part. The 
>> other part of this problem is that we have lots of logic sprinkled 
>> throughout our algorithms to enable them to handle both arrays and 
>> scalars.
> See comments below...
>> Secondly, I have just been bitten by this declaration which suggests 
>> that the new Numeric might handle default values better:.
>> _vp_mod = zeros(num_pts)
>> It would be less surprising to someone developing numeric algorithms 
>> if functions like this defaulted to creating a double precision array 
>> rather than integers.
> If you want a function that returns float arrays, it is trivial to 
> write and adds negligible overhead:
>     def float_array(array_spec):
>         return Numeric.array(array_spec, Numeric.Float)
> No need to interfere with Numeric's principle of "smallest usable 
> type", which fits well into the Python type promotion hierarchy.
> More generally, I don't think defaults should be chosen with a 
> particular application in mind. Arrays are a general and widely useful 
> datatype in many domains. I use integer arrays as much as float 
> arrays, even though my applications qualify as "numeric".

What I meant was that accidentally ommitting the na.Float in the 
declaration below introduced a hard to find bug in my code.

_vp_mod = na.zeros(num_pts, na.Float)

I had not heard of Numeric's "smallest usable type" principle. Even so, 
I would argue that for doing signal processing the smallest usable type 
is floating point :-)

> snipped >>
> Actually, all of your examples look like an attempt to recreate Matlab 
> behaviour. But Python is not Matlab!

Good point, and this code was actually written by developers who were 
porting libraries of Matlab code. I thought the examples illustrated a 
more general problem that was created by Numeric handling scalars 
differently to arrays.

In another post you said:

"... as the goal is inclusion into the Python core .... I propose that 
the PEP should include unification of scalars and arrays such that for 
all practical purposes scalars *are* rank-0 arrays. "

So I think we are in broad agreement.



> Konrad.
> -- 
> ---------------------------------------------------------------------
> Konrad Hinsen
> Laboratoire Léon Brillouin, CEA Saclay,
> 91191 Gif-sur-Yvette Cedex, France
> Tel.: +33-1 69 08 79 25
> Fax: +33-1 69 08 82 61
> E-Mail: hinsen at llb.saclay.cea.fr
> ---------------------------------------------------------------------
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
> _______________________________________________
> 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