[Numpy-discussion] converting scalar to array with dimension 1

Robert Kern robert.kern at gmail.com
Fri Mar 30 16:26:26 EDT 2007


Pierre GM wrote:
>Bill Baxter wrote:
>>   a = array(a, copy=0,ndmin=1)
>>
>> Anyway, sounds like premature optimization to me.
> 
> Ah, prematurity depends on the context, doesn't it ? Isn't there some famous 
> quote about two-liners ? Here, we have a function that does little more but 
> calling array(x,subok=True, copy=False, ndmin=1) in a loop. Is skipping the 
> loop for some very specific applications really premature ? For example, I 
> tend to use more and more the subok=True flag instead of 'asanyarray': is 
> there any 'official' recommendation about this ?

Well, Guido once mentioned a reasonable principle about API design: if your
function has an argument which is almost always going to be specified as a
literal (e.g. copy=False rather than copy=should_i_copy), then make separate
functions for each variant.

Note that the atleast_*() functions used to be not in Numeric. scipy had them in
scipy_base and used them so extensively (because they are incredibly useful for
writing generic and robust code) that they were added to numpy along with most
of the other stuff in scipy_base. True, not every two-liner should be in the
core, but very-frequently-used two-liners that state the authors intent clearer
can have a good case made for them.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list