LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   python : NumPy : Array, Matrix Formatting (http://www.linuxquestions.org/questions/programming-9/python-numpy-array-matrix-formatting-895464/)

cin_ 08-04-2011 02:22 AM

python : NumPy : Array, Matrix Formatting
 
pour posteritie,


Formatting with NumPy ...
"
One dimensional arrays are then printed as rows, bidimensionals as matrices and tridimensionals as lists of matrices.
"


Code is essentially...
Code:

import numpy as whatisgoingonwiththeformattingofmy
print 33
pseudomatrix = [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32] -- this repeats itself 29 times... -- [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]
]
print whatisgoingonwiththeformattingofmy.array([pseudomatrix])


And the output is...
Code:

# ./pseudomatrix
33
[[ 0  0  0 ...,  0  0  0]
 [ 0  1  2 ..., 30 31 32]
 [ 0  1  2 ..., 30 31 32]
 ...,
 [ 0  1  2 ..., 30 31 32]
 [ 0  1  2 ..., 30 31 32]
 [ 0  1  2 ..., 30 31 32]]

To remove this formatting built in,
Add this, or some variant, to your code...
Code:

import numpy as whatisgoingonwiththeformattingofmy
set_printoptions(threshold='nan')
set_printoptions(linewidth=100)
...


set_printoptions() : http://docs.scipy.org/doc/numpy/refe...ntoptions.html

EricTRA 08-05-2011 12:25 AM

Hi,

Thanks for sharing. Off the Zero Reply List.

Kind regards,

Eric

cin_ 08-05-2011 07:56 PM

Documentation
 
It originally began as a question.

I searched the forum and could not find anything... I am not authorised to create my own tags, but I though NumPy would have been a good tag for this post... so I decided to dig through the documentation.

Some time later I thought I'd share the conclusions to save others the time and give the forum another search result.


All times are GMT -5. The time now is 09:17 AM.