<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def inv(self):
 """inversion operation of self Returns ------- Matrix : Matrix inverse of self """


        if self.isdiagonal:
            inv = 1.0 / self.__x
            if (np.any(~np.isfinite(inv))):
                idx = np.isfinite(inv)
                np.savetxt("testboo.dat",idx)
                invalid = [self.row_names[i] for i in range(idx.shape[0]) if idx[i] == 0.0]
                raise Exception("Matrix.inv has produced invalid floating points " +
                                " for the following elements:" + ','.join(invalid))
            return type(self)(x=inv, isdiagonal=True,
                              row_names=self.row_names,
                              col_names=self.col_names,
                              autoalign=self.autoalign)
        else:
            return type(self)(x=la.inv(self.__x), row_names=self.row_names,
                              col_names=self.col_names,
                              autoalign=self.autoalign)