I want such type of output
[[ 1. 0. 0.]
[ 0. 1. 0.]
[ 0. 0. 1.]]
But I am getting This
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
My code is this :
import numpy
print(numpy.identity(size))
This should do the trick:
numpy.set_printoptions(formatter={'all': lambda x: " {:.0f} ".format(x)})
If you want to add the decimal point replace " {:.0f} " by " {:.0f}. "
You can modify the number of spaces or formatting in general in the lambda function.
use numpy.arrange(start, stop, size) as follow
import numpy as np
arr1 = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 0]])
arr2 = np.arange(1, 9, 1)
print(arr2)
output
[1 2 3 4 5 6 7 8]
np.set_print_options. But if you are anumpybeginner, I'd suggest focusing your learning elsewhere.