Question

In: Computer Science

Write a function softMax_M(Q) to return a 2darray of softmax function values ??ℎ=???ℎ−?∑??=1???ℎ−? for ?=0,1,⋯,?−1,ℎ=0,1,⋯,?−1 ,...

Write a function softMax_M(Q) to return a 2darray of softmax function values ??ℎ=???ℎ−?∑??=1???ℎ−? for ?=0,1,⋯,?−1,ℎ=0,1,⋯,?−1 , where ? is a 2darray of floats with shape ( ? , ? ), ??ℎ is the element at the (?+1) -th row and the (ℎ+1) -th column of array ? , and ? is the largest element in array ? . (Hint: operations should be performed down the rows; a returned 2darray and ? are of the same shape.) Sample: if D = np.array([[10, 9], [5, 6], [8, 4]]), then softMax_M(D) returns array([[0.876, 0.946], [0.006, 0.047], [0.118, 0.006]]).

in python program

Solutions

Expert Solution

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

#import numpy module
import numpy as np
#function which computes softmax function values for the given 1-d numpy array z.
def softMax(z):
#computing using softmax function formula
    return np.exp(z) / np.sum(np.exp(z), axis=0)
#1-d numpy array
z=np.array([[10, 9], [5, 6], [8, 4]])
#call softMax() and get the result
vec=softMax(z)
#Now vec contains the result but as expected in the problem the result should be rounded till 3 decimal places
vec=np.around(vec, decimals=3)
#after rounding print
print(vec)

Related Solutions

Write a function softMax_M(Q) to return a 2darray of softmax function values ??ℎ=???ℎ−?∑??=1???ℎ−? for ?=0,1,⋯,?−1,ℎ=0,1,⋯,?−1 ,...
Write a function softMax_M(Q) to return a 2darray of softmax function values ??ℎ=???ℎ−?∑??=1???ℎ−? for ?=0,1,⋯,?−1,ℎ=0,1,⋯,?−1 , where ? is a 2darray of floats with shape ( ? , ? ), ??ℎ is the element at the (?+1) -th row and the (ℎ+1) -th column of array ? , and ? is the largest element in array ? . (Hint: operations should be performed down the rows; a returned 2darray and ? are of the same shape.) Sample: if D =...
????????? ?ℎ? ??? ?? ?ℎ? ?????? ?? ?ℎ??ℎ ???ℎ ????? ???????? ?? ??????????: 1) ?(?, ?)...
????????? ?ℎ? ??? ?? ?ℎ? ?????? ?? ?ℎ??ℎ ???ℎ ????? ???????? ?? ??????????: 1) ?(?, ?) = ?−? 4−? 2− ?2 2) ?(?, ?, ?) = ln |? 2 + ? 2 − 6| ???? (? 2 − ? 2 + ? 2) 3) ℎ(?, ?, ?) = √? + 2? − ? ? 2 + ? 2
1-Consider the production function ? = ?? ?(?ℎ) 1−? . Transform the production function into per-worker...
1-Consider the production function ? = ?? ?(?ℎ) 1−? . Transform the production function into per-worker terms and show how growth in productivity can be estimated, even though it is not directly observable. Show your work
For this assignment you are expected to submit the following two files: 1. ????ℎ??????ℎ??????. ℎ 2....
For this assignment you are expected to submit the following two files: 1. ????ℎ??????ℎ??????. ℎ 2. ????ℎ??????ℎ??????. ??? You are being asked to write a class for simple weather data storage. Each instance of the class will hold data for exactly one month (30 days). Each day’s weather will be classified as either rainy (‘R’), cloudy (‘C’), or sunny (‘S’). To achieve this, your class will contain a character array of length 30. The class will provide three functions to...
In Python Create a function called ℎ?????. The function has as arguments a list called ??????...
In Python Create a function called ℎ?????. The function has as arguments a list called ?????? and a list call center. • List ?????? contains lists that represent points. o For example, if ?????? = [[4,2], [3,2], [6,1]], the list [4,2] represents the point with coordinate ? at 4 and y coordinate at 2, and so on for the other lists. Assume that all lists within points contain two numbers (that is, they have x, y coordinates). • List ??????...
1) Sketch the graph of the function ℎ(?) = ?^5⁄3 − 5?^2⁄3 , showing all work...
1) Sketch the graph of the function ℎ(?) = ?^5⁄3 − 5?^2⁄3 , showing all work for domain, intercepts, asymptotes, increase/decrease, relative extrema, and concavity. 2) For the function ?(?) = 2?^2−6/(?−1)^2 , find a) all intercepts, and b) all asymptotes. 3) Determine the concavity of the function ?(?) = ?^2?^−? . 4) Use properties of logarithms to rewrite the expression below as a sum, difference, or multiple of logarithms. ln ?(rad 3)√?^2 + 1 3 5) Use properties of...
Write a function softMax(x) to return a 1darray of softmax function values ??=???−?∑?−1?=0???−?fi=exi−m∑j=0K−1exj−m for ?=0,2,⋯,?−1i=0,2,⋯,K−1, where...
Write a function softMax(x) to return a 1darray of softmax function values ??=???−?∑?−1?=0???−?fi=exi−m∑j=0K−1exj−m for ?=0,2,⋯,?−1i=0,2,⋯,K−1, where ?x is a 1darray of ?K floats, ??xi is the (?+1)(i+1)-th element of array ?x, and ?m is the largest element in array ?x. Sample: if z = np.array([10, 5, 8]), then softMax(z) returns array([0.876, 0.006, 0.118]). in python program and the output should be array([0.876, 0.006, 0.118])
let f be the function on [0,1] given by f(x) = 1 if x is different...
let f be the function on [0,1] given by f(x) = 1 if x is different of 1/2 and 2 if x is equal to 1/2 Prove that f is Riemann integrable and compute integral of f(x) dx from 0 to 1 Hint for each epsilon >0 find a partition P so that Up (f) - Lp (f) <= epsilon
Write a function that will take in an array (of type double), and will return the...
Write a function that will take in an array (of type double), and will return the array with all of the elements doubled. You must use pass-by-reference and addressing and/or pointers to accomplish this task. C++
write a function named as cubeCalculator that takes an integer pointer as function and return its...
write a function named as cubeCalculator that takes an integer pointer as function and return its cube value , you are required to compute the cube of a number using pointer notation , return the result as an integer value , use c++
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT