[SciPy-dev] Octave array formatting examples
eric
eric at scipy.org
Mon Feb 18 01:31:43 CST 2002
Hey Fernando,
Here are some sample octave outputs. At the end is the output of the format
command options and their meanings for Octave.
octave:1> a = roots([1,2,3,4,5,6,7,8,9])
a =
-1.28876 + 0.44768i
-1.28876 - 0.44768i
-0.72436 + 1.13698i
-0.72436 - 1.13698i
0.13639 + 1.30495i
0.13639 - 1.30495i
0.87673 + 0.88137i
0.87673 - 0.88137i
octave:2> format long
octave:3> a
a =
-1.288756587957740 + 0.447682305901415i
-1.288756587957740 - 0.447682305901415i
-0.724360527656508 + 1.136975343061895i
-0.724360527656508 - 1.136975343061895i
0.136385310220365 + 1.304952920520545i
0.136385310220365 - 1.304952920520545i
0.876731805393882 + 0.881372126823502i
0.876731805393882 - 0.881372126823502i
octave:10> a = rand(5,5)
a =
Columns 1 through 4:
0.2383920848369598 0.4348705410957336 0.8961446881294250 0.6055997014045715
0.6609045863151550 0.5333006978034973 0.0284115206450224 0.2143878042697906
0.5080860257148743 0.1541089564561844 0.8641215562820435 0.5571301579475403
0.1096438020467758 0.9567501544952393 0.6171138286590576 0.9123255014419556
0.6439611911773682 0.1768558770418167 0.1341447830200195 0.2482996433973312
Column 5:
0.7593351602554321
0.6312018036842346
0.5956992506980896
0.1406104713678360
0.3457353711128235
octave:16> a = rand(5,5)+rand(5,5)*j
a =
Column 1:
0.6902413368225098 + 0.9270709753036499i
0.0714196115732193 + 0.9306957125663757i
0.4022956192493439 + 0.1311691850423813i
0.8854562044143677 + 0.0498457774519920i
0.8829681277275085 + 0.3563515543937683i
Column 2:
0.4604839682579041 + 0.3887093961238861i
0.6259743571281433 + 0.3982550501823425i
0.4543380439281464 + 0.5150275826454163i
0.6959248781204224 + 0.1767881363630295i
0.0839983001351357 + 0.6666156053543091i
Column 3:
0.7222939729690552 + 0.7316601276397705i
0.7881859540939331 + 0.1195990145206451i
0.0002050292678177 + 0.8647435903549194i
0.0405133590102196 + 0.4060045480728149i
0.8830721378326416 + 0.2345113456249237i
Column 4:
0.9146161675453186 + 0.3588070273399353i
0.1572253555059433 + 0.8799443244934082i
0.6621940135955811 + 0.0548975020647049i
0.3020973503589630 + 0.7739759683609009i
0.1915321201086044 + 0.8278477191925049i
Column 5:
0.2164765596389771 + 0.9701768159866333i
0.4962071478366852 + 0.0528524965047836i
0.9886205792427063 + 0.4764747023582458i
0.3292922079563141 + 0.4794612824916840i
0.9707457423210144 + 0.2543968856334686i
octave:17> format short
octave:18> a = rand(5,5)+rand(5,5)*j
a =
Columns 1 through 4:
0.6579 + 0.3181i 0.6785 + 0.1699i 0.8595 + 0.5765i 0.9841 + 0.9808i
0.1261 + 0.3136i 0.0035 + 0.0643i 0.4204 + 0.4313i 0.6348 + 0.4895i
0.4532 + 0.2377i 0.0467 + 0.0851i 0.1086 + 0.5233i 0.7480 + 0.5024i
0.3988 + 0.3001i 0.8262 + 0.2479i 0.6966 + 0.9397i 0.6697 + 0.5029i
0.1975 + 0.3135i 0.8525 + 0.3550i 0.8608 + 0.1164i 0.3418 + 0.3752i
Column 5:
0.4255 + 0.1573i
0.1951 + 0.3906i
0.4658 + 0.4730i
0.7997 + 0.6897i
0.5093 + 0.7083i
octave:4> help format
format is a built-in text function
- Command: format options
Control the format of the output produced by `disp' and Octave's
normal echoing mechanism. Valid options are listed in the
following table.
`short'
Octave will try to print numbers with at least 3 significant
figures within a field that is a maximum of 8 characters wide.
If Octave is unable to format a matrix so that columns line
up on the decimal point and all the numbers fit within the
maximum field width, it switches to an `e' format.
`long'
Octave will try to print numbers with at least 15 significant
figures within a field that is a maximum of 24 characters
wide.
As will the `short' format, Octave will switch to an `e'
format if it is unable to format a matrix so that columns
line up on the decimal point and all the numbers fit within
the maximum field width.
`long e'
`short e'
The same as `format long' or `format short' but always display
output with an `e' format. For example, with the `short e'
format, pi is displayed as `3.14e+00'.
`long E'
`short E'
The same as `format long e' or `format short e' but always
display output with an uppercase `E' format. For example,
with the `long E' format, pi is displayed as
`3.14159265358979E+00'.
`free'
`none'
Print output in free format, without trying to line up
columns of matrices on the decimal point. This also causes
complex numbers to be formatted like this `(0.604194,
0.607088)' instead of like this `0.60419 + 0.60709i'.
`bank'
Print in a fixed format with two places to the right of the
decimal point.
`+'
Print a `+' symbol for nonzero matrix elements and a space
for zero matrix elements. This format can be very useful for
examining the structure of a large matrix.
`hex'
Print the hexadecimal representation numbers as they are
stored in memory. For example, on a workstation which stores
8 byte real values in IEEE format with the least significant
byte first, the value of `pi' when printed in `hex' format is
`400921fb54442d18'. This format only works for numeric
values.
`bit'
Print the bit representation of numbers as stored in memory.
For example, the value of `pi' is
01000000000010010010000111111011
01010100010001000010110100011000
(shown here in two 32 bit sections for typesetting purposes)
when printed in bit format on a workstation which stores 8
byte real values in IEEE format with the least significant
byte first. This format only works for numeric types.
By default, Octave will try to print numbers with at least 5
significant figures within a field that is a maximum of 10
characters wide.
If Octave is unable to format a matrix so that columns line up on
the decimal point and all the numbers fit within the maximum field
width, it switches to an `e' format.
If `format' is invoked without any options, the default format
state is restored.
More information about the Scipy-dev
mailing list