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

2007-03-30 Thread Pierre GM
On Friday 30 March 2007 17:43:42 Bill Baxter wrote: > Actually I > didn't realize that it had a loop in it, so thanks for pointing that > out. I thought it was just and alias for array with some args. I just realized that myself, going directly in the sources: that's how I found that the ndmin

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

2007-03-30 Thread Bill Baxter
On 3/31/07, Pierre GM <[EMAIL PROTECTED]> wrote: > > > 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. > >

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

2007-03-30 Thread Pierre GM
On Friday 30 March 2007 16:26:26 Robert Kern wrote: > 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. Fair enough, I'll keep that in mind. Thanks again! __

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

2007-03-30 Thread Robert Kern
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

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

2007-03-30 Thread Pierre GM
> 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 prem

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

2007-03-30 Thread Bill Baxter
On 3/31/07, P GM <[EMAIL PROTECTED]> wrote: > Actually, there's even faster than that: > > a = 3 > a = array(a, ndmin=1) > > > atleast_1d is nothing but a wrapper function, that works best when used with > several inputs. When using only one array as inputs, the trick above should > be more appropr

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

2007-03-30 Thread P GM
Actually, there's even faster than that: a = 3 a = array(a, ndmin=1) atleast_1d is nothing but a wrapper function, that works best when used with several inputs. When using only one array as inputs, the trick above should be more appropriate. On 3/30/07, Bill Baxter <[EMAIL PROTECTED]> wrote

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

2007-03-30 Thread Bill Baxter
atleast_1d will do the trick In [11]: a = 3 In [12]: a = atleast_1d(a) In [13]: shape(a) Out[13]: (1,) In [14]: a.shape # also works ;-) Out[14]: (1,) In [15]: a[0] Out[15]: 3 --bb On 3/30/07, Mark Bakker <[EMAIL PROTECTED]> wrote: > Hello list - > > I have a function that normally accepts an

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

2007-03-30 Thread Mark Bakker
Hello list - I have a function that normally accepts an array as input, but sometimes a scalar. I figured the easiest way to make sure the input is an array, is to make it an array. But if I make a float an array, it has 0 dimension, and I can still not do array manipulation on it. a = 3 a = ar