Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Transpose matrix does not work when MatrixForm is used, why?

1,301 views
Skip to first unread message

steve_H

unread,
Dec 19, 2003, 7:27:41 AM12/19/03
to
hello

Mathematica 5.0

m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm
Transpose[m]

this just does nothing. it simply prints back what I typed with
m in MatrixForm but does not actually do the transpose.

But when I do

m = { {1, 2, 3}, {4, 5, 6} }
Transpose[m]


it works.

It seems that the function Transpose does not like to accept a
list in 'MatrixForm' ?

I use a MatrixForm to see the matrix better. Does this mean one have
to removed the MatrixForm each time before calling Transpose?

Florian Jaccard

unread,
Dec 20, 2003, 5:59:29 AM12/20/03
to
Just do :

(m = { {1, 2, 3}, {4, 5, 6} })//MatrixForm

and

Transpose[m]

will work !

Meilleures salutations

Florian Jaccard


-----Message d'origine-----
De : steve_H [mailto:nma...@hotmail.com]
Envoyé : ven., 19. décembre 2003 12:58
À : math...@smc.vnet.net
Objet : Transpose matrix does not work when MatrixForm is
used, why?

Owen, HL (Hywel)

unread,
Dec 20, 2003, 6:01:32 AM12/20/03
to
MatrixForm changes the list into a form suitable for displaying graphically.
In other words, MatrixForm[m] is not the same 'thing' as m.
m is a matrix, MatrixForm[m] is an object for displaying.

You should instead do:

m = { {1, 2, 3}, {4, 5, 6} }

m//MatrixForm to display it

Transpose[m]
Transpose[m]//MatrixForm to display the Transpose

There's no other way around it.

Jean.Pellegri

unread,
Dec 20, 2003, 6:02:33 AM12/20/03
to

"steve_H" <nma...@hotmail.com> a écrit dans le message de
news:bruqrt$t0p$1...@smc.vnet.net...

> hello
>
> Mathematica 5.0
>
> m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm
> Transpose[m]
>

Do this (take care at brackets):

(m = { {1, 2, 3}, {4, 5, 6} }) // MatrixForm

Transpose[m]

Ciao

--
< Jean Pellegri >
"fortitudo mea in rota"
F - 93100 Montreuil
I - 54023 Filattiera


David Park

unread,
Dec 20, 2003, 6:03:34 AM12/20/03
to
Use a set of parentheses...

(m = { {1, 2, 3}, {4, 5, 6} } ) // MatrixForm

Transpose[m] // MatrixForm

or try out TraditionalForm.

David Park
dj...@earthlink.net
http://home.earthlink.net/~djmp/


-----Original Message-----
From: steve_H [mailto:nma...@hotmail.com]
Subject: Transpose matrix does not work when MatrixForm is
used, why?


hello

Mathematica 5.0

m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm
Transpose[m]

this just does nothing. it simply prints back what I typed with


m in MatrixForm but does not actually do the transpose.

But when I do

m = { {1, 2, 3}, {4, 5, 6} }

Marcus Stollsteimer

unread,
Dec 20, 2003, 6:06:37 AM12/20/03
to
Try

( m = {{1,2,3},{4,5,6}} ) // MatrixForm
Transpose[m] // MatrixForm

(then m is defined as a list and then printed in matrix form)

MatrixForm[] is supposed for printing of matrices,
the functions for matrix manipulation cannot handle its output.

When you want to calculate with matrices you should define
your matrices as lists and use MatrixForm only for displaying
the results.

Regards,
Marcus

steve_H wrote:
> It seems that the function Transpose does not like to accept a
> list in 'MatrixForm' ?

Right


--
Is old age really so terrible?
Not if you've brushed your teeth faithfully! -- W. Allen

normal t-online.de

unread,
Dec 20, 2003, 6:09:43 AM12/20/03
to
Hi, that is no fake, because it is stored like this:

??m
m = MatrixForm[{{1, 2, 3}, {4, 5, 6}}]

If you type

(m = { {1, 2, 3}, {4, 5, 6} }) // MatrixForm

all is fine :-)

Regards

Peter Klamser

-----Ursprüngliche Nachricht-----
Von: steve_H [mailto:nma...@hotmail.com]
Gesendet: Freitag, 19. Dezember 2003 12:58
An: math...@smc.vnet.net
Betreff: Transpose matrix does not work when MatrixForm is
used, why?


hello

Mathematica 5.0

m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm
Transpose[m]

this just does nothing. it simply prints back what I typed with
m in MatrixForm but does not actually do the transpose.

But when I do

m = { {1, 2, 3}, {4, 5, 6} }
Transpose[m]


it works.

It seems that the function Transpose does not like to accept a
list in 'MatrixForm' ?

I use a MatrixForm to see the matrix better. Does this mean one have

Selwyn Hollis

unread,
Dec 20, 2003, 6:11:47 AM12/20/03
to
Here's the trick: Put parentheses around the assignment and put
//MatrixForm outside.

(m = { {1, 2, 3}, {4, 5, 6} } )// MatrixForm

-----
Selwyn Hollis
http://www.math.armstrong.edu/faculty/hollis

Peltio

unread,
Dec 20, 2003, 6:12:48 AM12/20/03
to
"steve_H" wrote


>m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm
>Transpose[m]
>
>this just does nothing.

>I use a MatrixForm to see the matrix better. Does this mean one have
>to removed the MatrixForm each time before calling Transpose?

No. Just add a couple of parenthesis, to let m be assigned to the matrix,
and not to an object with head MatrixForm:

( m = { {1, 2, 3}, {4, 5, 6} } ) // MatrixForm
Transpose[m]

cheers,
Peltio
--
Invalid address in reply-to. Crafty demunging required to mail me.

Tomas Garza

unread,
Dec 20, 2003, 6:13:49 AM12/20/03
to
The Help browser says: MatrixForm acts as a "wrapper" which affects
printing, but not evaluation. Hence you cannot take the Transpose of a
"wrapper". Perhaps you could rather do this:

In[3]:=
m={{1,2,3},{4,5,6}};
m//MatrixForm

In[5]:=
Transpose[m]//MatrixForm

This way you can perform the evaluations and then look at the results in a
nice way.

Tomas Garza
Mexico City

----- Original Message -----
From: "steve_H" <nma...@hotmail.com>
Subject: Transpose matrix does not work when MatrixForm is used,
why?


> hello
>
> Mathematica 5.0
>


> m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm
> Transpose[m]
>

> this just does nothing. it simply prints back what I typed with
> m in MatrixForm but does not actually do the transpose.
>
> But when I do
>

> m = { {1, 2, 3}, {4, 5, 6} }

> Transpose[m]
>
>
> it works.
>
> It seems that the function Transpose does not like to accept a
> list in 'MatrixForm' ?
>

Harold Noffke

unread,
Dec 20, 2003, 6:19:55 AM12/20/03
to
If you type ...

?Transpose

You get ...

"Transpose[list] transposes the first two levels in list. ... "

This tells you Transpose takes a List as an argument, rather than a
MatrixForm.

I think this could be corrected by Wolfram with a little code tinking,
because "transpose" is one of the well-defined operators in matrix
theory, so the average user expects Transpose to work on a MatrixForm
as well as on a List.

Harold

nma...@hotmail.com (steve_H) wrote in message news:<bruqrt$t0p$1...@smc.vnet.net>...

Bill Rowe

unread,
Dec 20, 2003, 6:20:57 AM12/20/03
to
On 12/19/03 at 6:57 AM, nma...@hotmail.com (steve_H) wrote:

> m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm
> Transpose[m]

> this just does nothing. it simply prints back what I typed with
> m in MatrixForm but does not actually do the transpose.

Right.

If your look a the Head of m, you will find it is MatrixForm rather than List. Consequently, Transpose doesnx't know what to do.

You can fix this in one of two ways. First, by forcing the m to be a list before doing MatrixForm as in:

(m = { {1, 2, 3}, {4, 5, 6} }) // MatrixForm

The other method which I prefer is to set the default output format as Traditional form. This will (amoung other things) cause a matrix to display as you want without having to type //MatrixForm.
--
To reply via email subtract one hundred and four

Bob Hanlon

unread,
Dec 20, 2003, 6:28:06 AM12/20/03
to
Use parentheses so that the assignment occurs before the MatrixForm is applied.

(m = {{1, 2, 3}, {4, 5, 6}}) // MatrixForm
Transpose[m]


Bob Hanlon

Bobby R. Treat

unread,
Dec 21, 2003, 3:52:20 AM12/21/03
to
Here's a "fix" -- add it to your Init.nb file:

Unprotect[Transpose ];
Transpose[MatrixForm[a_]] := MatrixForm[Transpose[a]]
Protect[Transpose];

Then this will probably do what you want:

m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm

m // Transpose

A more complete solution would do the same for other matrix functions.

Bobby

Harold...@wpafb.af.mil (Harold Noffke) wrote in message news:<bs1b8r$9m0$1...@smc.vnet.net>...

AES/newspost

unread,
Dec 21, 2003, 3:57:29 AM12/21/03
to
In article <bs1aln$9in$1...@smc.vnet.net>,
Kla...@t-online.de (normal t-online.de) wrote:

> If you type
>
> (m = { {1, 2, 3}, {4, 5, 6} }) // MatrixForm
>
> all is fine :-)
>

Oooh, that's another of those sneaky Mathematica expert tricks.

I'd been typing in

m = { {1, 2, 3}, {4, 5, 6} }; m// MatrixForm

to get the same result.

Bobby R. Treat

unread,
Dec 23, 2003, 5:17:24 AM12/23/03
to
The "wrapper" is very obviously affecting evaluation here, not just
printing. If you can't compute the Transpose... well, what evaluation
is NOT affected?

See my earlier message in the same thread for a remedy (not just a
dodge, like everybody else seems to be contributing).

Bobby

Tomas Garza <tgar...@prodigy.net.mx> wrote in message news:<bs1atd$9kj$1...@smc.vnet.net>...

Andrzej Kozlowski

unread,
Dec 23, 2003, 5:32:13 AM12/23/03
to
This of course works, but presumably he would want do this for other
functions, (e.g. Inverse etc), not just transpose. So it seems to me it
is easier simply to use Map:

m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm

Transpose/@m

etc.

Andrzej Kozlowski

On 21 Dec 2003, at 17:42, Bobby R. Treat wrote:

> Here's a "fix" -- add it to your Init.nb file:
>
> Unprotect[Transpose ];
> Transpose[MatrixForm[a_]] := MatrixForm[Transpose[a]]
> Protect[Transpose];
>
> Then this will probably do what you want:
>

> m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm

> m // Transpose
>
> A more complete solution would do the same for other matrix functions.
>
> Bobby
>
> Harold...@wpafb.af.mil (Harold Noffke) wrote in message
> news:<bs1b8r$9m0$1...@smc.vnet.net>...

Dr Bob

unread,
Dec 24, 2003, 4:39:23 AM12/24/03
to
That may be easier... if we are willing to constantly pay attention to
whether the target of Transpose is "wrapped" in MatrixForm or not.
(Transpose/@m if it's wrapped, Transpose@m if not.)

But if we want Help's claim that evaluation is not affected to be true (it
currently is NOT), then we have to redefine Transpose, Inverse, etc. as in
my example.

Only then would MatrixForm act properly as a wrapper, as intended.

Bobby

On Tue, 23 Dec 2003 18:38:10 +0900, Andrzej Kozlowski <ak...@mimuw.edu.pl>
wrote:

> This of course works, but presumably he would want do this for other
> functions, (e.g. Inverse etc), not just transpose. So it seems to me it
> is easier simply to use Map:
>

> m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm

> Transpose/@m
>
> etc.
>
> Andrzej Kozlowski
>
> On 21 Dec 2003, at 17:42, Bobby R. Treat wrote:
>
>> Here's a "fix" -- add it to your Init.nb file:
>>
>> Unprotect[Transpose ];
>> Transpose[MatrixForm[a_]] := MatrixForm[Transpose[a]]
>> Protect[Transpose];
>>
>> Then this will probably do what you want:
>>

>> m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm

>> m // Transpose
>>
>> A more complete solution would do the same for other matrix functions.
>>
>> Bobby
>>
>> Harold...@wpafb.af.mil (Harold Noffke) wrote in message
>> news:<bs1b8r$9m0$1...@smc.vnet.net>...

steve_H

unread,
Dec 24, 2003, 5:48:20 PM12/24/03
to
Dr Bob <dr...@bigfoot.com> wrote in message news:<bsbmsb$lr1$1...@smc.vnet.net>...

> That may be easier... if we are willing to constantly pay attention to
> whether the target of Transpose is "wrapped" in MatrixForm or not.
> (Transpose/@m if it's wrapped, Transpose@m if not.)
>
> But if we want Help's claim that evaluation is not affected to be true (it
> currently is NOT), then we have to redefine Transpose, Inverse, etc. as in
> my example.
>
> Only then would MatrixForm act properly as a wrapper, as intended.
>
> Bobby
>


> On Tue, 23 Dec 2003 18:38:10 +0900, Andrzej Kozlowski <ak...@mimuw.edu.pl>
> wrote:
>
> > This of course works, but presumably he would want do this for other
> > functions, (e.g. Inverse etc), not just transpose. So it seems to me it
> > is easier simply to use Map:
> >
> > m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm
> > Transpose/@m
> >
> > etc.
> >
> > Andrzej Kozlowski
> >


Correct Dr Bob,

But why do we have to resort to all these tricks? Why can't Mathematica just
accept a MatrixForm (or any other representation form) of the object
in its functions (Transpose in this example) just as well as the
list representation?

Each Mathematica function, where needed, could start by checking if this
'Wrapper' as you call it exists, and converts it to a list
representation (remove the wrapper), and do its thing on the list,
and at the end put the 'wrapper' around the result as needed and
return the result to the user?

This way one does not have to worry which form of an object one uses,
the representation form or the list form.

i.e. representation form will be transparent to all Mathematica functions.

Bobby R. Treat

unread,
Dec 27, 2003, 5:03:02 AM12/27/03
to
That's right; we shouldn't have to resort to any such tricks. Not when
Help explicitly says that evaluation isn't affected.

Bobby

nma...@hotmail.com (steve_H) wrote in message news:<bsd53k$r90$1...@smc.vnet.net>...

Kla...@t-online.de

unread,
Dec 27, 2003, 5:04:03 AM12/27/03
to
Hi,

why has Santa Claus a red cape on?

A deer is not a dog is not a dog.

A MatrixForm Object is not a Matrix.

m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm;
??m -> m = MatrixForm[{{1, 2, 3}, {4, 5, 6}}]

Therefore m[[0]] -> MatrixForm

But

(m = { {1, 2, 3}, {4, 5, 6} }) // MatrixForm;
??m -> m = {{1, 2, 3}, {4, 5, 6}}

Therefore m[[0]] -> List

Therefore again:

A MatrixForm Object is not a Matrix.

Regards

Peter Klamser


-----Ursprüngliche Nachricht-----
Von: steve_H [mailto:nma...@hotmail.com]

Gesendet: Mittwoch, 24. Dezember 2003 23:42
An: math...@smc.vnet.net
Betreff: Re: Transpose matrix does not work when MatrixForm is
used, why?


Andrzej Kozlowski

unread,
Dec 27, 2003, 5:06:06 AM12/27/03
to
Well, actually there is nothing to stop one doing this now.

In[1]:=
Unprotect[MatrixForm];

In[2]:=
MatrixForm/:f_[MatrixForm[expr_]]:=MatrixForm[f[expr]]

In[3]:=
Protect[MatrixForm];

In[4]:=
m={{1,2,3},{4,5,6},{0,1,0}}//MatrixForm

Now try:

Transpose[m]

or

Inverse[m]

As you see this seems to work already. Of course it still needs more
work: it should be extended to functions of several arguments with
MatrixForm heads, and one should also think more about unforeseen
consequences.
Still, I have to say that I have recently started (after years of
persuasion by Paul Abbott) to use TraditionalForm for input and output
and now I don't feel this sort of thing is needed. In fact it may not
always be what one wants. One example that comes to my mind is form my
own recent lectures on linear algebra when I used formulae with
MatrixForm wrapped around matrices when I did not want to expressions
(products) to evaluate.

Andrzej Kozlowski

On 25 Dec 2003, at 07:42, steve_H wrote:

> Dr Bob <dr...@bigfoot.com> wrote in message
> news:<bsbmsb$lr1$1...@smc.vnet.net>...
>

>> That may be easier... if we are willing to constantly pay attention to
>> whether the target of Transpose is "wrapped" in MatrixForm or not.
>> (Transpose/@m if it's wrapped, Transpose@m if not.)
>>
>> But if we want Help's claim that evaluation is not affected to be
>> true (it
>> currently is NOT), then we have to redefine Transpose, Inverse, etc.
>> as in
>> my example.
>>
>> Only then would MatrixForm act properly as a wrapper, as intended.
>>
>> Bobby
>>
>
>
>> On Tue, 23 Dec 2003 18:38:10 +0900, Andrzej Kozlowski
>> <ak...@mimuw.edu.pl>
>> wrote:
>>
>>> This of course works, but presumably he would want do this for other
>>> functions, (e.g. Inverse etc), not just transpose. So it seems to me
>>> it
>>> is easier simply to use Map:
>>>
>>> m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm
>>> Transpose/@m
>>>
>>> etc.
>>>
>>> Andrzej Kozlowski
>>>
>
>

Bobby R. Treat

unread,
Dec 28, 2003, 5:15:44 AM12/28/03
to
THANKS for emphasizing that MatrixForm and List are two different
heads. That's very, very true -- but rather obvious and not
particularly helpful.

The issue is that the MatrixForm "wrapper" affects evaluation,
contrary to the description in Help. The question is what to do about
it.

Thanks to Andrzej Kozlowski, we have a short answer that seems to
work.

Bobby

Kla...@t-online.de wrote in message news:<bsjlej$24e$1...@smc.vnet.net>...

Kla...@t-online.de

unread,
Dec 29, 2003, 12:25:36 AM12/29/03
to
Hi,

every modern computer program solves two problems:

1. The main problem (Mathematica solve mathematical problems)

2. Tell the user something about the found solution: The output!

Ancient computer program did not! They only solved the problem, the output
option was forgotten (ALGOL in the early sixties... ;-) => (because there
was not enough memory...).

The MatrixForm primitive is not a mathematical problem, it is one of the
second kind. Output has something to do with tradition, not so deep with the
problem itself...

Therefore the output primitives should not be locked with the problem
itself.

Some people want to have the same format each Mathematica session. Therefore
you find by some experts

http://www.verbeia.com/mathematica/tips/Tricks.html

or

http://www.verbeia.com/mathematica/tips/HTMLLinks/Tricks_174.html

$PrePrint=Which[MatrixQ[#],MatrixForm[#],NumberQ[#],#,True,Short[#,50]]&

Putting this into your init.m file in the kernel directory, you will have
never again to type //MatrixForm and you never have again to position the
brackets correct:

(m = { {1, 2, 3}, {4, 5, 6} }) // MatrixForm;

Regards

Peter


-----Ursprüngliche Nachricht-----
Von: Bobby R. Treat [mailto:dr...@bigfoot.com]
Gesendet: Sonntag, 28. Dezember 2003 11:11

Dr Bob

unread,
Dec 29, 2003, 12:28:41 AM12/29/03
to
I don't want to see EVERY matrix in MatrixForm -- it takes up too much
space on my screen, especially for a large matrix, where the screen isn't
even wide enough to see a row in that format.

Also, MatrixQ will test true for something I think of as a list of lists
(not a matrix).

Furthermore, MatrixForm is NOT a primitive. Mathematica doesn't have
primitives as such.

Bobby

Kla...@t-online.de

unread,
Dec 29, 2003, 12:29:42 AM12/29/03
to
Hi, for your purpose

(m = { {1, 2, 3}, {4, 5, 6} }) // MatrixForm;

is the best!

Where lies the problem positioning a pair of brackets?

Regards

Peter

-----Ursprüngliche Nachricht-----
Von: Dr Bob [mailto:dr...@bigfoot.com]
Gesendet: Sonntag, 28. Dezember 2003 20:42
An: Kla...@t-online.de; math...@smc.vnet.net
Betreff: Re: AW: Re: Transpose matrix does not work when

Dr Bob

unread,
Dec 29, 2003, 12:31:44 AM12/29/03
to
No, Andrzej's solution works much better. That way I get to see m in
MatrixForm every time it is displayed... and still do math with it.

Unprotect[MatrixForm];
MatrixForm /:
(f_)[MatrixForm[expr_,
opts___]] := MatrixForm[
f[expr], opts]
Protect[MatrixForm];


m = MatrixForm[{{1, 2, 3},

{4, 6, 5}, {9, 8, 7}}]
m
Transpose[m]
Inverse[m]

His solution isn't complete, as this doesn't work yet:

m.Inverse[m]

This takes care of that:

Unprotect[MatrixForm];
MatrixForm /: f_[MatrixForm[a_], MatrixForm[b_]] := MatrixForm[f[a, b]]
Protect[MatrixForm];

But then this still doesn't work:

m.m.m

But this does:

(m.m).m

The behavior I want is nothing more than what Help says is already there
-- MatrixForm shouldn't affect evaluation.

Bobby

0 new messages