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

Wayne Watson sierra_mtnview@sbcglobal....
Sat Dec 19 12:50:33 CST 2009

```I guess I'll become accustomed to it over time. I have some interesting
things to do for which I will need the facilities of numpy.

I realized where I got into trouble with some of this. I was not
differentiating between the dimensionality of space and that of a matrix
or array. I haven't had to crank out math and computer work for quite
awhile. Further, I've been doing a lot of reading on the Big Bang, and
the dimensionality of space. I'm presently strongly biased towards
thinking about space. For example, when I say 2D, I'm thinking of plane
geometry space, and 3D as the world we live in.

Thanks to all on this thread.

Christopher Barker wrote:
> Wayne Watson wrote:
>
>> Yes, flat sounds useful here. However, numpy isn't bending over
>> backwards to tie in conventional mathematical language into it.
>>
>
> exactly -- it isn't bending over at all! (well a little -- see below).
> numpy was designed for general purpose computational needs, not any one
> branch of math. nd-arrays are very useful for lots of things. In
> contrast, Matlab, for instance, was originally designed to be an easy
> front-end to linear algebra package. Personally, when I used Matlab, I
> found that very awkward -- I was usually writing 100s of lines of code
> that had nothing to do with linear algebra, for every few lines that
> actually did matrix math. So I much prefer numpy's way -- the linear
> algebra lines of code are longer an more awkward, but the rest is much
> better.
>
> The Matrix class is the exception to this: is was written to provide a
> natural way to express linear algebra. However, things get a bit tricky
> when you mix matrices and arrays, and even when sticking with matrices
> there are confusions and limitations -- how do you express a row vs a
> column vector? what do you get when you iterate over a matrix? etc.
>
> There has been a bunch of discussion about these issues, a lot of good
> ideas, a little bit of consensus about how to improve it, but no one
> with the skill to do it has enough motivation to do it.
>
> As for your problem, I think a 3-d euclidean vector is well expressed as
> a (3,) shape array, and then you don't need flat, etc.
>
> In [6]: v1 = np.array((1,2,3), dtype=np.float)
>
> In [7]: v2 = np.array((3,1,2), dtype=np.float)
>
> In [8]: np.dot(v1,v2)
> Out[8]: 11.0
>
> -Chris
>
>
>
>
>
>
>
>
>> I don't recall flat in any calculus books. :-) Maybe I've been away so
>> long from it, that it is a common math concept? Although I doubt that.
>>
>>
>> Alan G Isaac wrote:
>>
>>> On 12/19/2009 11:45 AM, Wayne Watson wrote:
>>>
>>>
>>>> A 4x1, 1x7, and 1x5 would be examples of a 1D array or matrix, right?
>>>>
>>>> Are you saying that instead of using a rotational matrix  ...
>>>> 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?
>>>>
>>>> To get the scalar value (sum of squares) I had to use a transpose, T, on
>>>> one argument.
>>>>
>>>>
>>> At this point, you have raised some long standing issues.
>>> There are a couple standard replies people give to some of them.
>>> E.g.,
>>>
>>> 1. don't use matrices, OR
>>> 2. don't mix the use of matrices and arrays
>>>
>>> Matrices are *always* 2d (e.g., a "row vector" or a "column vector" is 2d).
>>> So in fact you should find it quite natural that that transpose was needed.
>>> Matrices change * to matrix multiplication and ** to matrix exponentiation.
>>> I find this very convenient, especially in a teaching setting, so I use
>>> NumPy matrices all the time.   Many on this list avoid them completely.
>>>
>>> Again, if you want a *scalar* as the product of vectors for which you
>>> created matrix objects (e.g., a and b), you can just use flat:
>>> np.dot(a.flat,b.flat)
>>>
>>> hth,
>>> Alan Isaac
>>> _______________________________________________
>>> NumPy-Discussion mailing list
>>> NumPy-Discussion@scipy.org
>>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>>
>>>
>>>
>
>
>

--

(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/>

```