[Numpy-discussion] matrix wart
Konrad Hinsen
konrad.hinsen at laposte.net
Fri Feb 22 02:50:42 EST 2008
On 22.02.2008, at 01:10, Alan G Isaac wrote:
> Someone once pointed out on this list that one might
> consider a matrix to be a container of 1d vectors. For NumPy,
> however, it is natural that it be a container of 1d arrays.
> (See the discussion for the distinction.)
If I were to design a Pythonic implementation of the mathematical
concept of a matrix, I'd implement three classes: Matrix,
ColumnVector, and RowVector. It would work like this:
m = Matrix([[1, 2], [3, 4]])
m[0, :] --> ColumnVector([1, 3])
m[:, 0] --> RowVector([1, 2])
m[0,0] --> 1 # scalar
m.shape --> (2, 2)
m[0].shape --> (2,)
However, the matrix implementation in Numeric was inspired by Matlab,
where everything is a matrix. But as I said before, Python is not
Matlab.
Konrad.
More information about the NumPy-Discussion
mailing list