How can you print sub-arrays in numpy the same way Matlab does? I have a 3 by 10000 array and I want to view the first 20 columns. In Matlab you can write
a=zeros(3,10000);
a(:,1:20)
  Columns 1 through 15
 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     0     0     0     0     0     0     0     0     0     0     0
  Columns 16 through 20
 0     0     0     0     0
 0     0     0     0     0
 0     0     0     0     0
However in Numpy
import numpy as np
set_printoptions(threshold=nan)
a=np.zeros((3,10000))
print a[:,0:20]
[[  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.   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.   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.   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.   0.   0.   0.   0.   0.   0.
    0.   0.   0.   0.   0.   0.   0.   0.]]
As you can see numpy prints the first row, then the second row, then the third row. I would like it to maintain the column structure and not the row structure
Thank you very much
PS: One solution would be for example
print a[:,0:20].T
[[  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.   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.]]
but, would consume a lot more of space on screen than desired. it would be great if numpy had this option
Does this give what you want?
>>> for item in a[:,0:20].T:
    print '\t'.join(map(str,item.tolist()))
Or this?
>>> for item in a[:,0:20]:
    print '\t'.join(map(str,item.tolist()))
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With