Python3 Define h(x) =-exp - Write a function h x) for computing h(x) according t
ID: 3725962 • Letter: P
Question
Python3
Define h(x) =-exp - Write a function h x) for computing h(x) according to the formula given above. (x may be a float or an array. Write your code so that it can handle both of these. This doesn't need an if statement or anything, just you to be aware of possible input values.) Next, use np. Linspace to create two arrays, xarray and harray, which contain x and hx) values respectively, for 41 uniformly spaced x coordinates, x E -4,4] Your submission should include definitions for function h and arrays xarray and harray. Many are still confusing printing a value and returning a value. Don't confuse those! and h) values respectively Keep in mind throughout that NumPy arrays require NumPy functions, not those from mathExplanation / Answer
import numpy as np def h(x): return (1/(2*np.pi)**(.5))*np.exp(-.5*np.asarray(x)**2) xarray=np.linspace(-4,4,41) harray=h(xarray)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.