[Numpy-discussion] objects are not aligned. Matrix and Array

Charles R Harris charlesr.harris@gmail....
Fri Dec 18 23:43:41 CST 2009


On Fri, Dec 18, 2009 at 10:20 PM, Wayne Watson <sierra_mtnview@sbcglobal.net
> wrote:

> This program gives me the message following it:
> ================Program==========
> import numpy as np
> from numpy import matrix
> import math
>
>
You don't want math.


> def sinD(D): # given in degrees, convert to radians
>    return math.sin(math.radians(D))
> def cosD(D):
>    return math.cos(math.radians(D))
>
>
def sinD(D):
    return np.sin(np.deg2rad(D))


> r = math.sqrt(2*2+5*5)
>

np.hypot(2, 5)


> print r
> m1 = matrix([[2], [5]])
> print "m1: ", m1
>
> theta = 5.0 # degrees
> #CW 2x2 clockwise matrix
> rotCW = matrix([ [cosD(theta), sinD(theta)], [-sinD(theta), cosD(theta)] ])
>
> print rotCW
>
> m2 = rotCW*m1
> print "m2: ", m2
> print "aaaaaaaa: ", type(m1), type(m2)
> m1=np.array(m1)
> m2=np.array(m2)
>
> print "zzzzzzzz: ", type(m1), type(m2)
>
> print"dot, ..."
> dotres = np.dot(m1,m2)
>

Try np.dot(m2, m1), m1 is a column matrix.


> print "dotres", dotres
> ==============end==========
>
> ==========Output msgs========
> 5.38516480713
> m1:  [[2]
>  [5]]
> [[ 0.9961947   0.08715574]
>  [-0.08715574  0.9961947 ]]
> m2:  [[ 2.42816811]
>  [ 4.806662  ]]
> aaaaaaaa:  <class 'numpy.core.defmatrix.matrix'> <class
> 'numpy.core.defmatrix.matrix'>
> zzzzzzzz:  <type 'numpy.ndarray'> <type 'numpy.ndarray'>
> dot, ...
>
> Traceback (most recent call last):
>  File
>
> "C:/Sponsor_Meteors/Sentinel_Development/Development_Sentuser+Utilities/Playground/junk.py",
> line 30, in <module>
>    dotres = np.dot(m1,m2)
> ValueError: objects are not aligned
> ================end msgs===========
> Why the msg? The types look alike and each array/matrix contains two
> elements..
>
>
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20091218/b823a4aa/attachment.html 


More information about the NumPy-Discussion mailing list