[Numpy-discussion] Changing a matrix element into a scalar

Joshua Holbrook josh.holbrook at gmail.com
Tue Aug 3 14:51:01 EDT 2010


On Tue, Aug 3, 2010 at 10:44 AM, Alan G Isaac <alan.isaac at gmail.com> wrote:
> On 8/3/2010 1:29 PM, Joshua Holbrook wrote:
>> What's the
>> advantage of the matrix datatype?
>
>
> As it turns out, that's a controversial question.  ;-)
>
> One answer: pedagogy (for those used to matrices).
>
> A related answer: succinctness and readability of *some* code.
>
>         >>> a,b,c = np.array([[1,2,3]]), np.array([[4],[5],[6]]), np.arange(9).reshape((3,3))
>         >>> d = np.dot(b,np.dot(a,c))   # matrix multiplication
>         >>> d2 = b.dot(a.dot(c))        # NumPy 1.5+
>         >>> d5 = d.dot(d).dot(d).dot(d).dot(d)  #matrix exponentiation
>         >>> d[0,0] = 0
>         >>> di = np.linalg.inv(d)       #matix inverse
>         >>> A,B,C = np.mat('1 2 3'), np.mat('4;5;6'), np.mat(np.arange(9).reshape((3,3)))
>         >>> D = B * (A * C)             #matrix multiplication
>         >>> D5 = D**5                   #matrix exponentiation
>         >>> D[0,0] = 0
>         >>> DI = D.I                    #matix inverse
>
> fwiw,
> Alan Isaac
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>

I see. Thanks Alan!

--Josh



More information about the NumPy-Discussion mailing list