MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / relu

Function relu

neural_network/activation_functions/rectified_linear_unit.py:18–37  ·  view source on GitHub ↗

Implements the relu function Parameters: vector (np.array,list,tuple): A numpy array of shape (1,n) consisting of real values or a similar list,tuple Returns: relu_vec (np.array): The input numpy array, after applying relu. >>> vec = np.array([-1

(vector: list[float])

Source from the content-addressed store, hash-verified

16
17
18def relu(vector: list[float]):
19 """
20 Implements the relu function
21
22 Parameters:
23 vector (np.array,list,tuple): A numpy array of shape (1,n)
24 consisting of real values or a similar list,tuple
25
26
27 Returns:
28 relu_vec (np.array): The input numpy array, after applying
29 relu.
30
31 >>> vec = np.array([-1, 0, 5])
32 >>> relu(vec)
33 array([0, 0, 5])
34 """
35
36 # compare two arrays and then return element-wise maxima.
37 return np.maximum(0, vector)
38
39
40if __name__ == "__main__":

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected