Ask Your Question
0

Why doesn't show() render latex properly?

asked 2020-02-19 13:25:25 +0100

eod gravatar image

updated 2020-02-19 13:30:06 +0100

The following code:

import numpy as np

P = np.matrix('0 0 20 20; 0 20 20 0')

show(P)

Gives me the output

[[๐Ÿถ๐Ÿถ๐Ÿธ๐Ÿถ๐Ÿธ๐Ÿถ]
 [๐Ÿถ๐Ÿธ๐Ÿถ๐Ÿธ๐Ÿถ๐Ÿถ]]

In old sage, I guess around 6.0 or something, the show() command would render a proper latex matrix. I.e like you would see in a mathematics textbook.

Is there any way I can get this functionality back?

Thanks.

Edit: I'm using Sage 9.0 v 0.6.0 on Windows.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-02-19 13:56:08 +0100

rburing gravatar image

I don't know how it used to work, but the way I understand it is that NumPy's matrix type is not a SageMath data type, so it doesn't support SageMath's latex rendering (in particular, it doesn't have a _latex_() method).

So just convert to a SageMath data type first:

sage: show(matrix(P))

$$\left(\begin{array}{rrrr} 0 & 0 & 20 & 20 \\ 0 & 20 & 20 & 0 \end{array}\right)$$

edit flag offensive delete link more

Comments

Hmm, the matrix command gives me an error in jupyter for both sage 8.0 an 9.0 -- but it works in the console. Any idea why?

eod gravatar imageeod ( 2020-02-19 15:39:08 +0100 )edit

What is the error?

rburing gravatar imagerburing ( 2020-02-19 15:40:55 +0100 )edit

When I try to use the matrix command I get:

TypeError: 'numpy.ndarray' object is not callable

eod gravatar imageeod ( 2020-02-19 15:45:03 +0100 )edit

What code do you use as input, exactly?

rburing gravatar imagerburing ( 2020-02-19 15:46:55 +0100 )edit

For example "matrix([[1,2],[3,4]])" as copied from the sagemath docs.

eod gravatar imageeod ( 2020-02-19 16:21:30 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-02-19 13:25:25 +0100

Seen: 569 times

Last updated: Feb 19 '20