<jupyter_start><jupyter_text>E2.1 The unique values of a vectorUsing just for loop, get the unique values in a vector. Ex.: for a vector ``v = [1, 1, 2, 3, 4, 3]``, the out put will be a vector ``u = [1, 2, 3, 4]``. Make it a function and do not use numpy. Also, make use of the code that checks if an element occurs from yesterday. Make it a function too.<jupyter_code>def unique(v):
    return True

v = [1, 1, 2, 3, 4, 3]
u = unique(v)

print("The unique values in u are: " + str(u))<jupyter_output>The unique values in u are: True<jupyter_text>E2.2 Replacing values in a vectorYou are given a vector ``v`` and a number ``n``. Make a function that replaces all the occurrences of ``n`` in ``v`` by the number 1 and all the other elements by the number ``-1``. Ex.: if ``v = [1, 2, 1, 5, 2]`` and ``n = 2``, the output is ``v_new = [-1, 1, -1, -1, 1]``. Do not use numpy in this problem.<jupyter_code>def replace_numbers(v, n):  
    return True

v, n = [1, 2, 1, 5, 2], 2
v_new = replace_numbers(v, n)

print("The new vector is: "  + str(v_new))<jupyter_output>The new vector is: True<jupyter_text>If you could use numpy, how would you change the function above? Hint: it is related to the function ``np.zeros()``.<jupyter_code>import numpy as np

def replace_numbers(v, n):  
    return True

v, n = [1, 2, 1, 5, 2], 2
v_new = replace_numbers(v, n)

print("The new vector is: "  + str(v_new))<jupyter_output>The new vector is: True<jupyter_text>The difference between these functionis quite silly, but it will be useful in the future.  E2.3 Returning the sign of a dot productYou are given $x$ of length $d$ and $w$ of length $d + 1$. Make a function that returns the sign (if positive, return 1 and, if negative, return -1) of the expression $v \cdot x + b$, where $v$ is $w$ up to the second to last element and $b$ is its last element. Use the function ``np.sign()``.<jupyter_code>def sign_dot(x, w):
    return True

w = [2, 1, 30]
x = [3, 4]

print("The sign dot is " + str(sign_dot(x, w)))<jupyter_output>The sign dot is True<jupyter_text>E2.4 Operations on matrices column-wise Maximum and minimumYou are given a matrix. Your task is to find the maximum and the maximum and the minimum values of each column and store them in two vectors (one for the maximum values and another one for the minumum values)<jupyter_code># TODO<jupyter_output><empty_output><jupyter_text>Indices of the maximum and minimum valuesNow, get the indices of the maximum and minimum values in each column. Store them in two vectors as above.<jupyter_code># TODO<jupyter_output><empty_output><jupyter_text>Summing and AveragingCompute the sum and the average of each column. Store them in two vectors as above.<jupyter_code># TODO<jupyter_output><empty_output><jupyter_text>Numpy powerLastly, go to the numpy documentation and code the same as above using the functions ``np.max``, ``np.min``, ``np.argmax``, ``np.argmin``, ``np.sum`` and ``np.mean``.<jupyter_code># TODO<jupyter_output><empty_output><jupyter_text>E2.6 Drawing functionsHere I'd like you to draw the following functions with $x$ ranging from $-5$ to $5$:- $f(x) = \tanh(x)$ (Hyperbolic Tagent) , on a blue solid line;- $f(x) = 1/(1+e^{-z})$ (Sigmoid), on a green dashed line;- $f(x) = \max(0, x)$ (ReLU - Rectified Linear Unit), on a magenta solid line;- $f(x) = \text{sign}(x)$ (Step or Sign function), on a red dotted line.Also, add a grid to the plot, add a legend with the name of each function make the lines 2 mm wide and make the axis of the plot be limited by ``x_min = -5``, ``x_max = -5``, ``y_min = -1.2`` and ``y_max = 1.2``. Check this [this link](https://matplotlib.org/users/pyplot_tutorial.html) for more info or ask the teacher/TA if you have any question.  E2.5  Challenge: Find Index of ConvergenceSuppose that the function called "seq" defines a sequence, where the input $n$ is an index and the output is the $n$-th term in the sequence. Write a function where the input is any $\epsilon>0$ and the output is some $N$ such that $\vert x_n-x^\star\vertN$, so $N$ is the index of convergence.<jupyter_code>import numpy as np

def seq(n):
    return 2-1/n**2

v       = np.linspace(-1, 1, 200)
epsilon = True<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1219106463878327, 'fraction_numerical': 0.019724334600760455, 'mean_word_length': 4.341370558375634, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 34, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '117408', 'license': 'MIT', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1420, 'n_words': 626, 'path': 'Course Notebooks/Lecture 2 - Exercises.ipynb', 'repo_name': 'MeMeBigProgrammer/BrownMachineLearning', 'size': '4208'}