I have an array that is 1d, and I would like to print it as a column.
r1 = np.array([54,14,-11,2])
print r1
gives me this:
 [ 54  14 -11   2]
and
 print r1.shape
gives me this:
(4L,)
Is there something I can plug into np.reshape() so that
print r1.shape
gives me this?
(,4L)
And the printed output looks something like
 54
 14
-11
 2
                No, you can't do that unless you create a vertical version of your array. But if you just want to print your items in that format you can use set_printoptions() function to set a printing format for your intended types:
In [43]: np.set_printoptions(formatter={'int':lambda x: '{}\n'.format(x)})
In [44]: print(r1)
[54
 14
 -11
 2
]
NOTE: If you want to apply this function to all types you can use 'all' keyword that applies the function on all the types.
formatter = {'all':lambda x: '{}\n'.format(x)}
                        This will work:
import numpy as np
r1 = np.array([54,14,-11,2])
r1[:, None]
# array([[ 54],
#        [ 14],
#        [-11],
#        [  2]])
                        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