Ask Your Question

Get a matrix to display answers as decimals/floats, not fraction?

asked 2013-06-29 01:07:37 -0500

bxdin gravatar image

I searched and couldn't find a viable solution:

I successfully executed the following:

ma = matrix([[25, 5, 1], [49, 7, 1], [81, 9, 1]])
mb = matrix([[1121], [626], [967]])
ms = ma^-1 * mb

Unfotunately though, the statement, show(ms), displays the answer/values as fractions, meaning I have to manually enter each of the value 3 separate times, as part of a float function, i.e., float(fraction/number).

How can I force show(ms), to display the values as decimals?

Also I find the matrix more readable/writable if I can enter each row's values by their own line, instead of the same line, as seen on the the, ma= & mb= statements. I remember I could this with ease in MatLab. I'd appreciate knowing how to that as well.

This post also has an unanswered question if anyone is up for the challenge, :P, j/k:

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-06-29 01:52:58 -0500

pkoprowski gravatar image

1) You can easily write matrix "multilined". By default Python joins lines if the first one contains an opening bracket/parenthesis. Hence you can easily write:

ma = matrix([
[25, 5, 1], 
[49, 7, 1], 
[81, 9, 1]])
mb = matrix([

2) In order to display matrix entries as decimals you may convert a matrix base field to RDF like this:

ms = ma^-1 * mb
show(matrix(RDF, ms))

or alternatively:

edit flag offensive delete link more


Thanks :D.

bxdin gravatar imagebxdin ( 2013-06-29 02:07:47 -0500 )edit

another simple way: ms.n()

ndomes gravatar imagendomes ( 2013-06-29 02:08:29 -0500 )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


Asked: 2013-06-29 01:07:37 -0500

Seen: 1,346 times

Last updated: Jun 29 '13