How to implement the ReLU function in Numpy

后端 未结 9 1027
野性不改
野性不改 2020-12-02 09:53

I want to make a simple neural network which uses the ReLU function. Can someone give me a clue of how can I implement the function using numpy.

9条回答
  •  情深已故
    2020-12-02 10:15

    numpy didn't have the function of relu, but you define it by yourself as follow:

    def relu(x):
        return np.maximum(0, x)
    

    for example:

    arr = np.array([[-1,2,3],[1,2,3]])
    
    ret = relu(arr)
    print(ret) # print [[0 2 3] [1 2 3]]
    

提交回复
热议问题