First of all, i have an output array like this (in the matrix of 4×1) :
array([[ -2.22044605e-15],
[ 2.82842712e+01],
[ -2.22044605e-15],
[ 2.82842712e+01]])
and that output, i receive from return value of matrix multiplication of 4×3 and 3×1 just like below:
def inverse_kinematic(self,Degree):
# [W] = (1/r)[R][V]
self.R = array ( [[-1, 1, self.X1+self.Y1], [1, 1, self.X2-self.Y2],
[-1, 1, self.X3+self.Y3], [1, 1, self.X4-self.Y4]])
self.V = array ( [[self.Vt*math.cos(math.radians(Degree))],
[self.Vt*math.sin(math.radians(Degree))],[ self.Wv]])
self.W = []
self.W = (1/self.r)*dot(self.R,self.V)
return self.W
and i really want to have and output array like above but in two digit decimal value, like this:
array([[ 0.00],
[ 28.28],
[ 0.00],
[ 28.28]])
i have tired to use something like “%.2f” % (number) method and still not success. i wondering is there any best method to set decimal values in list of arrays?
Best Regards,
Glenn
Your return values are of very different orders:
2.82842712e+01 approximately 2.8
-2.22044605e-15 = 0.0000000000000022 approximately 0
It is likely that you have a numeric evaluation that is analytically zero and the small value is just a computation error.
Matrix operations are easily done in numpy, you could use something like this:
In that case you might be happy with
numpy arrays are convenient, because you don’t have to iterate over their entries: