Skip to main content
added 73 characters in body
Source Link
user1786283
user1786283

Try using np.vectorize:

printer = np.vectorize(lambda x:'{0:5}'.format(x,))
print printer(b).astype(object)

Or try using np.set_printoptions:

Exactly as shown in IDLE:

>>>x=np>>> import numpy as np
>>> x=np.random.random(10) 
>>>print(>>> x)
array([ 0.0797939772239823,  0.0707837769938461,  0.5195370585466846,  0.2694969703294278,  0.9511419706698482,
        0.41241448
04137562,  0.325879384223521 ,  0.9128238581317235,  0.0172536762221494,  0.34671691]6205595 ])
>>>np>>> np.set_printoptions(precision=3)
>>>print>>> print(x)
[ 0.08 722  0.071699  0.52 855  0.269033  0.951067  0.412041  0.326422  0.913813  0.017622  0.347]621]

Try using np.vectorize:

printer = np.vectorize(lambda x:'{0:5}'.format(x,))
print printer(b).astype(object)

Or try using np.set_printoptions:

>>>x=np.random.random(10) 
>>>print(x)
[ 0.07979397  0.07078377  0.51953705  0.26949697  0.95114197  0.41241448
  0.32587938  0.91282385  0.01725367  0.34671691]
>>>np.set_printoptions(precision=3)
>>>print(x)
[ 0.08   0.071  0.52   0.269  0.951  0.412  0.326  0.913  0.017  0.347]

Try using np.vectorize:

printer = np.vectorize(lambda x:'{0:5}'.format(x,))
print printer(b).astype(object)

Or try using np.set_printoptions:

Exactly as shown in IDLE:

>>> import numpy as np
>>> x=np.random.random(10)
>>> x
array([ 0.72239823,  0.69938461,  0.85466846,  0.03294278,  0.06698482,
        0.04137562,  0.4223521 ,  0.81317235,  0.62221494,  0.6205595 ])
>>> np.set_printoptions(precision=3)
>>> print(x)
[ 0.722  0.699  0.855  0.033  0.067  0.041  0.422  0.813  0.622  0.621]
Source Link
user1786283
user1786283

Try using np.vectorize:

printer = np.vectorize(lambda x:'{0:5}'.format(x,))
print printer(b).astype(object)

Or try using np.set_printoptions:

>>>x=np.random.random(10) 
>>>print(x)
[ 0.07979397  0.07078377  0.51953705  0.26949697  0.95114197  0.41241448
  0.32587938  0.91282385  0.01725367  0.34671691]
>>>np.set_printoptions(precision=3)
>>>print(x)
[ 0.08   0.071  0.52   0.269  0.951  0.412  0.326  0.913  0.017  0.347]