[Numpy-discussion] lstsq functionality
Keith Goodman
kwgoodman at gmail.com
Wed Jul 21 23:57:15 EDT 2010
On Wed, Jul 21, 2010 at 8:24 PM, Charles R Harris
<charlesr.harris at gmail.com> wrote:
>
> On Wed, Jul 21, 2010 at 5:44 PM, Keith Goodman <kwgoodman at gmail.com> wrote:
>> Can someone confirm that the copy in np.linalg.lstsq
>>
>> bstar[:b.shape[0],:n_rhs] = b.copy()
>>
>> is not needed? I'm assuming that ndarray.__setitem__ never gives a
>> view of the right-hand side.
>> ________
>
> bstar doesn't share memory with b, so there is no need for a copy. The whole
> first part of lstsq could use a cleanup, there are a lot of other things
> that could be made cleaner and some other bits that don't look right. Anyone
> want to take a shot at it?
>
> Chuck
Some minor tweaks suggestions:
>> b = np.random.rand(1000)
>> timeit b[:,newaxis] # actual
1000000 loops, best of 3: 1.03 us per loop
>> timeit b.reshape(-1,1) # alternative
1000000 loops, best of 3: 445 ns per loop
>>
>> timeit len(b.shape) # actual
10000000 loops, best of 3: 145 ns per loop
>> timeit b.ndim # alternative
10000000 loops, best of 3: 74.1 ns per loop
More information about the NumPy-Discussion
mailing list