[Numpy-discussion] matrix indexing question
Thu Mar 29 20:43:39 CDT 2007
On Mar 29, 2007, at 6:48 PM, Alan G Isaac wrote:
> On Thu, 29 Mar 2007, Bill Spotz apparently wrote:
>> What I envisioned was that M[i,:] would return
>> a row_vector and M[:,j] would return a column_vector,
>> because this would be symmetric behavior. M[i], by
>> convention, would behave the same as M[i,:].
> Can you please be explicit about the value added by that
> convention, as you see it?
I assume by "convention" you are referring to the convention that M
[i] is M[i,:] is a row_vector. I see it as a design decision:
Does M[i] mean something?
Then raise an exception. If users want to iterate over M,
this forces them to use the double index notation to specify
what they are iterating over. I would find this acceptable.
What should M[i] represent/return?
Array representing row vector:
Array representing column vector:
I would argue against linear algebra objects returning raw
arrays because their meaning/interface can be ambiguous, as
this thread demonstrates
Reasonable choice, analogous to conventional mathematical
Reasonable choice, but less analogous to conventional
Of all the choices, raising an exception and returning a row_vector
are (in my opinion, anyway) the best. Unless someone has a better
> Thank you,
> Alan Isaac
> PS I assume your "vector" class would always accept a single index,
> for both row and column vectors? What is the return type of v[i]?
My best guess at a best design would be that it would return a scalar.
And yes, vectors would always accept a single index. But because
they are matrices, they would accept two indexes as well.
> Numpy-discussion mailing list
** Bill Spotz **
** Sandia National Laboratories Voice: (505)845-0170 **
** P.O. Box 5800 Fax: (505)284-5451 **
** Albuquerque, NM 87185-0370 Email: email@example.com **
More information about the Numpy-discussion