Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Norms Note: In addition to regular p-norms, we will use the 0.5-norm below. By this we mean that you should use the expression for the

image text in transcribedimage text in transcribed

Norms Note: In addition to regular p-norms, we will use the "0.5-norm" below. By this we mean that you should use the expression for the p-norm with p = 0.5. Note that this is not actually a norm. Your task: With respect to each norm, plot a 2D ball with radius r centered around the origin using 500 points. (That is, plot the ball made of all 2D vectors w that satisfy the equation (wl=r for the p-norm.) Save a plot's axes using plt.gca(). For example: plt. figure() # ... code for the plot... fig_1 = plt.gca() Your code should produce the following four plots: 1. Draw the radius r 2D ball with respect to the 1-norm and save the plot to fig_1. 2. Draw the radius r 2D ball with respect to the 2-norm and save the plot to fig_2. 3. Draw the radius r 2D ball with respect to the 5-norm and save the plot to fig_3. 4. Draw the radius r 2D ball with respect to the "0.5-norm" and save the plot to fig_4. The setup code gives the following variables: Name Type float Description so-called radius of the norm ball Your code snippet should define the following variables: Name fig_1 fig_2 fig_3 fig_4 Type what plt.gca() returns what plt.gca() returns what plt.gca() returns what plt.gca() returns Description plot in 1 norm plot in 2 norm plot in 5 norm plot in 0.5 norm user_code.py 1 2 import matplotlib.pyplot as plt import numpy as np 4 # It may be helpful to complete this function 5- def norm(x, p): return (***p). sum() ** (1./p) Args: x (ndarray): input array p (int or float): order of the norm 12 Returns: (float): the p-norm of the array pass 17 ps = [1, 2, 5, 0.5] phi = np.linspace(0, 2 * np.pi, 500) unit_circle = n .array([np.cos(phi), np.sin(phi)]) 19 Restore original file Norms Note: In addition to regular p-norms, we will use the "0.5-norm" below. By this we mean that you should use the expression for the p-norm with p = 0.5. Note that this is not actually a norm. Your task: With respect to each norm, plot a 2D ball with radius r centered around the origin using 500 points. (That is, plot the ball made of all 2D vectors w that satisfy the equation (wl=r for the p-norm.) Save a plot's axes using plt.gca(). For example: plt. figure() # ... code for the plot... fig_1 = plt.gca() Your code should produce the following four plots: 1. Draw the radius r 2D ball with respect to the 1-norm and save the plot to fig_1. 2. Draw the radius r 2D ball with respect to the 2-norm and save the plot to fig_2. 3. Draw the radius r 2D ball with respect to the 5-norm and save the plot to fig_3. 4. Draw the radius r 2D ball with respect to the "0.5-norm" and save the plot to fig_4. The setup code gives the following variables: Name Type float Description so-called radius of the norm ball Your code snippet should define the following variables: Name fig_1 fig_2 fig_3 fig_4 Type what plt.gca() returns what plt.gca() returns what plt.gca() returns what plt.gca() returns Description plot in 1 norm plot in 2 norm plot in 5 norm plot in 0.5 norm user_code.py 1 2 import matplotlib.pyplot as plt import numpy as np 4 # It may be helpful to complete this function 5- def norm(x, p): return (***p). sum() ** (1./p) Args: x (ndarray): input array p (int or float): order of the norm 12 Returns: (float): the p-norm of the array pass 17 ps = [1, 2, 5, 0.5] phi = np.linspace(0, 2 * np.pi, 500) unit_circle = n .array([np.cos(phi), np.sin(phi)]) 19 Restore original file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions

Question

Explain the functions of financial management.

Answered: 1 week ago

Question

HOW MANY TOTAL WORLD WAR?

Answered: 1 week ago

Question

Discuss the scope of financial management.

Answered: 1 week ago

Question

Discuss the goals of financial management.

Answered: 1 week ago