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

Pierre GM pgmdevlist@gmail....
Fri Mar 30 15:14:59 CDT 2007


> I think you'll want to add the copy=False arg if you go that route, or
> else you'll end up with something that's much slower than atleast_1d
> for any array that gets passed in.  :-)

Yep indeed. We can also add the subok=True flag.

>   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 ?


More information about the Numpy-discussion mailing list