[PYTHON MATRIX-SIG] identity? and asarray?
Doug Heisterkamp
drh@oasis.unl.edu
Mon, 12 Aug 1996 17:03:25 -0500 (CDT)
Hi,
The function identity(n) does not return an n by n identity matrix. If
the current definition is changed from:
def identity(n):
return resize([1]+n*[n], (n,n))
to
def identity(n):
return resize([1]+n*[0], (n,n))
then it does what I think the function means. The asarray(a,t) function
is not returning a new matrix of type t. To do so, change from:
def asarray(a, typecode=None):
if type(a) == arraytype and (typecode == None or typecode == a.typecode()):
return a
elif typecode == None:
return array(a)
else:
return a
to
def asarray(a, typecode=None):
if type(a) == arraytype and (typecode == None or typecode == a.typecode()):
return a
elif typecode == None:
return array(a)
else:
return array(a,typecode)
When should a.asType(t) be use instead of asarray(a,t)? Is asType faster,
always give a new copy, and/or safe?
Doug Heisterkamp
drh@oasis.unl.edu
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================