[Numpy-discussion] zeros() default type in Numeric3

Perry Greenfield perry at stsci.edu
Mon Mar 28 08:18:16 EST 2005


On Mar 28, 2005, at 10:43 AM, Robert Kern wrote:

> Stephen Walton wrote:
>> zeros() in Numeric3 defaults to typecode='d' while in numarray it 
>> defaults to typecode=None, which in practice means 'i' by default.  
>> Is this deliberate? Is this desirable?  I'd vote for zeros(), ones() 
>> and the like to default to 'i' or 'f' rather than 'd' in the interest 
>> of space and speed.
>
> For zeros() and ones(), I don't think space and speed are going to be 
> affected by the default typecode. In my use of these functions, I 
> almost always need a specific typecode. If I use the default, it's 
> because I actually need the default typecode. Unfortunately, I almost 
> always want Float and not Int, so all of my code is littered with
>
>   zeros(shape, Float)
>
> I'll bet Travis's code looks the same.
>
> I would *love* to be able to spell these things like
>
>   Float.zeros(shape)
>   UInt8.ones(shape)
>   Complex32.array(other)
>   ...

This is an odd thought but why not:

Float(shape) # defaults to 0
UInt(shape, value=1)

I forget if it was proposed to make the type object a constructor for 
arrays in which case this may conflict with the usage of converting the 
argument of the callable form to an array, i.e.,

Float((2,3)) --> array([2.,3.], typecode=Float) # or whatever the name 
of the type parameter becomes






More information about the NumPy-Discussion mailing list