[Numpy-discussion] matrix indexing question
Colin J. Williams
Tue Mar 27 13:39:22 CDT 2007
Alan G Isaac wrote:
> On Mon, 26 Mar 2007, "Colin J. Williams" apparently wrote:
>> One would expect the iteration over A to return row
>> vectors, represented by (1, n) matrices.
> This is again simple assertion.
> **Why** would "one" expect this?
> Some people clearly do not.
> One person commented that this unexpected behavior was
> a source of error in their code.
> Another person commented that they did not even guess that
> such a thing would be possible.
> Experience with Python should lead to the ability to
> anticipate the outcome. Apparently this is not the case.
> That suggests a design problem.
> What about **Python** would lead us to expect this behavior??
> In *contrast*, everyone agrees that for a matrix M,
> we should get a matrix from M[0,:].
> This is expected and desirable.
Perhaps our differences lies in two things:
1. the fact that the text books typically take the column vector as the
default. For a Python version, based on C it makes more sense to treat
the rows as vectors, as data is stored contiguously by row.
2. the convention has been proposed that the vector is more conveniently
implemented as a matrix, where one dimension is one. The vector could be
treated as a subclass of the matrix but this adds complexity with little
clear benefit. PyMatrix has matrix methods isVector, isCVector and
I can see some merit in conforming to text book usage and would be glad
to consider changes when I complete the port to numpy, in a few months.
> Alan Isaac
More information about the Numpy-discussion