[Numpy-discussion] dot function or dot notation, matrices, arrays?

Wayne Watson sierra_mtnview@sbcglobal....
Sat Dec 19 11:45:02 CST 2009


OK, so what's your recommendation on the code I wrote?  Use shape 0xN? 
Will that eliminate the need for T?

I'll go back to Tenative Python, and re-read dimension, shape and the like.

Charles R Harris wrote:
>
>
> On Sat, Dec 19, 2009 at 9:45 AM, Wayne Watson 
> <sierra_mtnview@sbcglobal.net <mailto:sierra_mtnview@sbcglobal.net>> 
> wrote:
>
>
>
>     Dag Sverre Seljebotn wrote:
>     > Wayne Watson wrote:
>     >
>     >> I'm trying to compute the angle between two vectors in three
>     dimensional
>     >> space. For that, I need to use the "scalar (dot) product" ,
>     according to
>     >> a calculus book (quoting the book) I'm holding in my hands
>     right now.
>     >> I've used dot() successfully to produce the necessary angle. My
>     program
>     >> works just fine.
>     >>
>     >> In the case of the dot(function), one must use np.dev(x.T,x),
>     where x is
>     >> 1x3.
>     >>
>     >> I'm not quite sure what your point is about dot()* unless you are
>     >> thinking in some non-Euclidean fashion. One can form
>     np.dot(a,b) with a
>     >> and b arrays of 3x4 and 4x2 shape to arrive at a 3x2 array. That's
>     >> definitely not a scalar. Is there a need for this sort of
>     calculation in
>     >> non-Euclidean geometry, which I have never dealt with?
>     >>
>     >
>     > There's a difference between 1D and 2D arrays that's important
>     here. For
>     > a 1D array, np.dot(x.T, x) == np.dot(x, x), since there's only one
>     > dimension.
>     >
>     A 4x1, 1x7, and 1x5 would be examples of a 1D array or matrix, right?
>
>
> No, they are all 2D. All matrices are 2D. An array is 1D if it doesn't 
> have a second dimension, which might be confusing if you have only 
> seen vectors represented as arrays. To see the number of dimensions in 
> a numpy array, use shape:
>
> In [1]: array([[1,2],[3,4]])
> Out[1]:
> array([[1, 2],
>        [3, 4]])
>
> In [2]: array([[1,2],[3,4]]).shape
> Out[2]: (2, 2)
>
> In [3]: array([1,2, 3,4])
> Out[3]: array([1, 2, 3, 4])
>
> In [4]: array([1,2, 3,4]).shape
> Out[4]: (4,)
>
>
>     Are you saying that instead of using a rotational matrix like
>        theta = 5.0 # degrees
>        m1 = matrix([[2] ,[5]])
>        rotCW = matrix([ [cosD(theta), sinD(theta)], [-sinD(theta),
>     cosD(theta)] ])
>         m2= rotCW*m1
>        m1=np.array(m1)
>        m2=np.array(m2)
>     that I should use a 2-D array for rotCW? So why does numpy have a
>     matrix
>     class?  Is the class only used when working with matplotlib?
>
>
> Numpy has a matrix class because python lacks operators, so where * 
> normally means element-wise multiplication the matrix class uses it 
> for matrix multiplication, which is different. Having a short form for 
> matrix multiplication is sometimes a convenience and also more 
> familiar for folks coming to numpy from matlab.
>  
>
>     To get the scalar value (sum of squares) I had to use a transpose,
>     T, on
>     one argument.
>
>
> That is if the argument is 2D. It's not strictly speaking a scalar 
> product, but we won't go into that here ;)
>  
> <snip>
>
> Chuck
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>   

-- 
           Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

             (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
              Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet  
                
             "... humans'innate skills with numbers isn't much
              better than that of rats and dolphins." 
                       -- Stanislas Dehaene, neurosurgeon 
 
                    Web Page: <www.speckledwithstars.net/>



More information about the NumPy-Discussion mailing list