[Numpy-discussion] matrix indexing question
Colin J. Williams
cjw@sympatico...
Sun Mar 25 18:34:38 CDT 2007
Bill Baxter wrote:
> On 3/26/07, Alan G Isaac <aisaac@american.edu> wrote:
>>> Em Dom, 2007-03-25 às 13:07 -0400, Alan G Isaac escreveu:
>>>> >>> x[1]
>>>> matrix([[1, 0]])
>>>> feels wrong. (Similarly when iterating across rows.)
>>
>> On Sun, 25 Mar 2007, Paulo Jose da Silva e Silva apparently wrote:
>>> I think the point here is that if you are using matrices,
>>> then all you "should" want are matrices, just like in
>>> MATLAB:
>>> >> b = A(1, :)
>>> b =
>>> 1 2
>>
>> Yes, that is the idea behind this, which I am also
>> accustomed to from GAUSS. But note again that the Matlab
>> equivalent ::
>>
>> >>> x=N.mat('1 2;3 4')
>> >>> x[0,:]
>> matrix([[1, 2]])
>>
>> does provide this behavior. The question I am raising
>> is a design question and is I think really not addressed
>> by the rule of thumb you offer. Specifically, that rule
>> of thumb if it is indeed the justification of ::
>>
>> >>> x[1]
>> matrix([[3, 4]])
>>
>> finds itself in basic conflict with the idea that I ought to
>> be able to iterate over the objects in an iterable container.
>>
>> I mean really, does this not "feel" wrong? ::
>>
>> >>> for item in x: print item.__repr__()
>> ...
>> matrix([[1, 2]])
>> matrix([[3, 4]])
>
> This may sound silly, but I really think seeing all those brackets is
> what makes it feel wrong. Matlab's output doesn't put it in your
> face that your 4 is really a matrix([[4]]), even though that's what it
> is to Matlab. But I don't see a good way to change that behavior.
>
> The other thing I find problematic about matrices is the inability to
> go higher than 2d. To me that means that it's impossible to go "pure
> matrix" in my code because I'll have to switch back to arrays any time
> I want more than 2d (or use a mixed solution like a list of matrices).
> Matlab allows allows >2D.
>
> --bb
"pure matrix" seems to me an area of exploration, does it have any
application in numerical computation at this time?
A list of matrices seems to be a logical structure. PyMatrix deals with
lists in building a larger matrix from sub-matrices.
Suppose that we have matrices A (3, 4), B (3, 6), C (4, 2) and D (4, 8).
Then E= M([[A, B], [C, D]]) gives E (7, 10).
Colin W.
More information about the Numpy-discussion
mailing list