. I need help with the __add__(self, other) and __sub__(self, other) methods in Python. I put the starter code at the end.



In this problem, you'll implement a mathematical vector class. While the vectors are generally depicted as columns, you'll use a tuple. A vector of size \( n \in\{1,2,3, \ldots\} \) is a collection of real numbers: \[ \mathbf{x}=\left[\begin{array}{c} x_{1} \\ x_{2} \\ \vdots \\ x_{n} \end{array}\right] \] Given \( \mathbf{x}, \mathbf{y} \) are vectors of size \( n \) and \( z \) is a real number-we can define the following operations \[ \begin{array}{l} \mathbf{x}+\mathbf{y}=\left[\begin{array}{c} x_{1} \\ x_{2} \\ \vdots \\ x_{n} \end{array}\right]+\left[\begin{array}{c} y_{1} \\ y_{2} \\ \vdots \\ y_{n} \end{array}\right]=\left[\begin{array}{c} x_{1}+y_{1} \\ x_{2}+y_{2} \\ \vdots \\ x_{n}+y_{n} \end{array}\right] \\ \mathbf{x}-\mathbf{y}=\left[\begin{array}{c} x_{1} \\ x_{2} \\ \vdots \\ x_{n} \end{array}\right]-\left[\begin{array}{c} y_{1} \\ y_{2} \\ \vdots \\ y_{n} \end{array}\right]=\left[\begin{array}{c} x_{1}-y_{1} \\ x_{2}-y_{2} \\ \vdots \\ x_{n}-y_{n} \end{array}\right] \\ \mathbf{x} \times \mathbf{y}=\sum_{i=1}^{n} x_{i} y_{i} \\ z \times \mathbf{x}=z \times\left[\begin{array}{c} x_{1} \\ x_{2} \\ \vdots \\ x_{n} \end{array}\right]=\left[\begin{array}{c} z \times x_{1} \\ z \times x_{2} \\ \vdots \\ z \times x_{n} \end{array}\right] \\ -\mathbf{x}=\left[\begin{array}{c} -x_{1} \\ -x_{2} \\ \vdots \\ -x_{n} \end{array}\right] \\ |\mathbf{x}|=a b s(\mathbf{x})=\sqrt{\mathbf{x} \times \mathbf{x}} \\ \end{array} \] Two vectors \( \mathbf{x}, \mathbf{y} \) are equal if \( x_{i}=y_{i} \) for \( 1 \leq i \leq n \). The class you'll build will work for any non-zero length vector. The class constructor is: Assignment ?10 Classes, SQL, Random Walks Page 4
\( \begin{array}{ll}1 & \text { class Vector: } \\ 2 & \text { def __init___ }(\text { self, } \star x): \\ 3 & \text { self.__v }=x\end{array} \) The \( { }^{*} \mathrm{X} \) means you are making the arguments a tuple-further, a tuple can be sent if it has *. For example, \( 1 w=\operatorname{Vector}(*(10,10)) \) will send the tuple as a tuple-this makes arguments easier. For a vector \( \mathbf{x} \) of length \( n \), print \( (\mathbf{x}) \) should display \( 1 \) Here are instances and outputs: with output: \( \begin{array}{ll}1 & \langle 1,2\rangle\langle 3,-1\rangle\langle 0,3,2><-1,-1,-1\rangle \\ 2 & <4,1\rangle\langle-1,2,1\rangle \\ 3 & 1-5 \\ 4 & <5,10><0,15,10> \\ 5 & 2.236067977499793 .605551275463989 \\ 6 & <-1,-2>\langle 0,-3,-2> \\ 7 & \text { True True }\end{array} \)
\# PR0BLEM TWO class Vector: def _init_(self, \( * x) \) : self._v \( =x \) def get_tuple(self): pass def _add_(self, other): pass def _sub_(self, other): pass def _rmul_(self, other): return self. mul_(other) def _mul_(self, other): if type(other) in (int, float): return Vector(*(i*other for \( i \) in self._v)) else: return round(sum( \( [i * j \) for \( i, j \) in zip(self._v, other.get_tuple( ) ) ]), 3) def _abs_(self): pass def _neg_(self): pass def _eq_(self, other): pass def _repr_(self): return str(self._v). replace("(")," \( \left(^{\prime \prime}\right) \). replace(") ", "'>")