On 1/1/07, Colin J. Williams <[EMAIL PROTECTED]> wrote:
What is the best way to treat scalar values from a matrix?
It seems that it's best to treat them as a simple Python values and not
to leave them wrapped up in the ndarray structure. I would welcome
advice.
The problem is illustrated below.
Colin W.
# tMul.py
import numpy.core as _n
a= _n.arange(12).reshape((3, 4))
b= _n.arange(12).reshape((4, 3))
c= _n.dot(a, b)
print `c`
amat= _n.mat(a)
bmat= _n.mat(b)
cmat= amat*bmat
print cmat
print _n.dot(amat, _n.mat(5))
mat(5) is a 1x1 matrix:
In [5]: mat(5)
Out[5]: matrix([[5]])
so the error is valid. If you want to do a scalar multiply try
In [6]: amat*5
Out[6]:
matrix([[ 0, 5, 10, 15],
[20, 25, 30, 35],
[40, 45, 50, 55]])
This is an example where using arrays, as opposed to matrices, is perhaps
less confusing.
Chuck
_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion