[Numpy-discussion] My identity

Keith Goodman kwgoodman@gmail....
Mon Jul 20 13:17:16 CDT 2009

On Mon, Jul 20, 2009 at 10:53 AM, Pauli Virtanen<pav+sp@iki.fi> wrote:
> On 2009-07-20, Keith Goodman <kwgoodman@gmail.com> wrote:
> [clip]
>> Oh, sorry, I misunderstood. Yes, a similar change was made to eye but
>> not to identity.
> Nasty, duplicated code there it seems...


def myidentity2(n, dtype=None):
    return eye(n, M=n, k=0, dtype=dtype)

>> timeit myidentity(10)
100000 loops, best of 3: 7.15 µs per loop
>> timeit eye(10)
100000 loops, best of 3: 8.42 µs per loop
>> timeit myidentity2(10)
100000 loops, best of 3: 9 µs per loop

There also a second identity in np.matlib that has its own code. That
could be changed to

def myidentity2_matlib(n, dtype=None):
    return asmatrix(eye(n, M=n, k=0, dtype=dtype))


def myidentity2_matlib(n, dtype=None):
    return asmatrix(myidentity2(n, dtype))

More information about the NumPy-Discussion mailing list