Python coding !! please help for the second part don\'t know how to code it plea
ID: 3787817 • Letter: P
Question
Python coding !! please help for the second part don't know how to code it please!!!
Part 2: Norms Here we will investiage norms a little bit further. Recall from class that a 'norm' is a measure of size of a vector. The L1 norm is the sum of the absolute values of each component: The L2 norm is the square root of the sum of the squares ofeach component: And the infinity norm is the largest component (maximum absolute value): 2.0 Computing Norms: Please define three functions, one for each of the three norms listed above. The functions should take in two real numbers, a and b and return another real number, the 'size'. In [80]: Fill in these functions with the approriate code. def llnorm (a, b): return abs (a abs (b) def 12norm (a, b): return np. sqrt (a *2+b**2) def linf norm (a, b) return max abs (a), abs (b)) print (llnorm (1,1)) prints (12norm (1,1)) print (linfnorm (2,1)) 1.41421356237Explanation / Answer
Try out this code:
Since i don't have function "matrix_to_scatter_2d" , so i can't able to plot it.
import numpy as np
def unit_ballanswer(n,norm):
data_matrix=np.matrix(" ; ")
for i in range(n):
a=np.random.uniform(-1.1,1.1)
b=np.random.uniform(-1.1,1.1)
if(norm(a,b)<0):
new=np.matrix([[a], [b]])
data_matrix=np.concatenate((data_matrix,new),axis=1)
return data_matrix
x=unit_ballanswer(100,l1norm)
matrix_to_scatter_2d(x)
y=unit_ballanswer(100,l2norm)
matrix_to_scatter_2d(y)
x=unit_ballanswer(100,linfnorm)
matrix_to_scatter_2d(x)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.