“Softmax -Funktion Python” Code-Antworten

Softmax -Funktion Python

def softmax(x):
    return np.exp(x) / np.sum(np.exp(x), axis=0)
Victorious Vole

Eine Softmax -Funktion

import numpy as np
def softmax(x):
    """Calculates the softmax for each row of the input x.

    Your code should work for a row vector and also for matrices of shape (m,n).

    Argument:
    x -- A numpy matrix of shape (m,n)

    Returns:
    s -- A numpy matrix equal to the softmax of x, of shape (m,n)
    """
    
    #(≈ 3 lines of code)
    # Apply exp() element-wise to x. Use np.exp(...).
    # x_exp = ...

    # Create a vector x_sum that sums each row of x_exp. Use np.sum(..., axis = 1, keepdims = True).
    # x_sum = ...
    
    # Compute softmax(x) by dividing x_exp by x_sum. It should automatically use numpy broadcasting.
    # s = ...
    
    # YOUR CODE STARTS HERE
    x_exp = np.exp(x)
    x_sum = np.sum(x_exp, axis=1, keepdims=True)
    s=x_exp/x_sum
    
    # YOUR CODE ENDS HERE
    
    return s
josh.ipynb

Ähnliche Antworten wie “Softmax -Funktion Python”

Fragen ähnlich wie “Softmax -Funktion Python”

Weitere verwandte Antworten zu “Softmax -Funktion Python” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen