Sep-24-2018, 12:55 AM
Firstly, you can directly subtract
Secondly, this is probably just a display issue.
Try adding this line before you print the array:
My results:
numpy
arrays; no need for numpy.subtract
.Secondly, this is probably just a display issue.
-2*10**-16
is basically zero with some added floating point imprecision.Try adding this line before you print the array:
np.set_printoptions(suppress=True)Not sure why you are getting this behavior by default though.
My results:
import numpy as np a= [[ 1.0, 0.85979163, 0.0, 0.11766047, 0.19353699], [ 0.8589698, 1.0, 0.24111901, 0.0, 0.0 ], [ 0., 0.24554123, 1.0, 0.09234979, 0.07125199], [ 0.31269982, 0.22558714, 0.29298401, 1.0, 0.475543 ], [ 0.18880995, 0.0, 0.06580817, 0.32276821, 1.0 ]] b = np.ones((5,5), dtype=int) print(b - a)
Output:[[0. 0.14020837 1. 0.88233953 0.80646301]
[0.1410302 0. 0.75888099 1. 1. ]
[1. 0.75445877 0. 0.90765021 0.92874801]
[0.68730018 0.77441286 0.70701599 0. 0.524457 ]
[0.81119005 1. 0.93419183 0.67723179 0. ]]