It shows me like {{0}, {1}, {0}, {-1}} . Is it possible to make it look like a vector, always?
- 124,525
- 11
- 401
- 574
- 1,253
- 1
- 9
- 17
2 Answers
Add this to your notebook or init file
$PrePrint = If[MatrixQ[#], MatrixForm[#], #] &;
Then all matrices will automatically display as MatrixForm

and

If you want to format lists as column vectors also, try
$PrePrint =
Which[MatrixQ[#], MatrixForm[#], VectorQ[#], ColumnForm[#],
True, #] &;
Now also

- 143,286
- 11
- 154
- 359
As @kattern pointed out, MatrixForm will pretty print your lists to look like matrices.
{{0}, {1}, {0}, {-1}} // MatrixForm

A word of caution, however: MatrixForm can get in the way of your calculations if you are not careful. See this question and the related answers: Why does MatrixForm affect calculations?.
For instance, you could get bitten by something like this:
matWRONG = {{0}, {1}, {0}, {-1}} // MatrixForm
(matCORRECT = {{0}, {1}, {0}, {-1}}) // MatrixForm

Both expressions print out a nice formatted version of your vector, but there is a subtle difference.
- In the first case, you assigned the graphical output of
MatrixForm, i.e. the pretty-printed form, to the variablematWRONG. That's probably not what you meant to do. - The second version assigns the vector to the
matCORRECTvariable, then pretty-prints the value of that variable. The variable itself contains the vector, and can be further operated upon.
For instance, you can transpose the matCORRECT vector, but if you try to do the same on the matWRONG one, Transpose will not recognize its input as a vector and return unevaluated, and you will probably be confused.
Transpose[matCORRECT]
Transpose[matWRONG]

-
-
@grdgfgr As far as I know, it won't. In my understanding, in that case the pretty-printing will happen "last", i.e. after the assignments etc have already been taken care of. – MarcoB May 18 '15 at 03:28
MatrixFormis what you are looking for. – Kattern May 18 '15 at 02:36$PrePrintsolution in this Q&A: (3098). Perhaps this question should be close as a duplicate of that more elaborate one? – Mr.Wizard May 18 '15 at 06:07