[Numpy-discussion] matrices in 1.1

Stéfan van der Walt stefan@sun.ac...
Sat Mar 22 17:21:32 CDT 2008


Hi Alan

On Sat, Mar 22, 2008 at 5:49 PM, Alan G Isaac <aisaac@american.edu> wrote:
>  Are you trying to suggest that in most matrix programming
>  languages if you extract a row you will then need to use two
>  indices to extract an element of that row?  This does not
>  match my experience.  I would ask you to justify that by
>  listing the languages you have in mind.

No, I agree with you that that is unintuitive -- but it can be solved
by introducing Row and ColumnVectors, which are still 2-dimensional.
One important result you don't want is:

In [9]: x = np.array([[1,2,3],[4,5,6],[7,8,9]])

In [10]: x[:,0]
Out[10]: array([1, 4, 7])

But instead the current behaviour:

In [11]: x = np.matrix([[1,2,3],[4,5,6]])

In [12]: x[:,0]
Out[12]:
matrix([[1],
        [4]])

>  Remember, you will still be able to extract the first row of
>  a matrix ``M`` as  a **submatrix** using ``M[0,:]``.
>  No functionality would be lost under my proposed change.

Do I understand correctly that you want M[0,:] and M[0] to behave
differently?  Would you like M[0] to return the first element of the
matrix as in Octave?  Is there a reason why the Column/Row-vector
solution wouldn't work for you?

>  In short, the behavior change I have requested will
>  - mean that habits formed using ndarrays transfer naturally
>   to the use of matrices

But other habits, such as x[0,:] and x[0] meaning the same thing,
won't transfer so well.  So you're just swapping one set of
inconveniences for another.

I'm not trying to sabotage your proposal, I just want to understand it
better.  If I'm the only one who is not completely satisfied, then
please, submit a patch and have it applied.

Regards
Stéfan


More information about the Numpy-discussion mailing list