Numpy 颈部乙状结肠功能

Numpy 颈部乙状结肠功能,numpy,sigmoid,Numpy,Sigmoid,为了快速计算,我必须在Numpy中实现我的sigmoid函数这是下面的代码 def sigmoid(Z): """ Implements the sigmoid activation in bumpy Arguments: Z -- numpy array of any shape Returns: A -- output of sigmoid(z), same shape as Z cache -- returns Z, use

为了快速计算,我必须在Numpy中实现我的sigmoid函数这是下面的代码

   def sigmoid(Z):
    """
    Implements the sigmoid activation in bumpy

    Arguments:
    Z -- numpy array of any shape

    Returns:
    A -- output of sigmoid(z), same shape as Z
    cache -- returns Z, useful during backpropagation
    """

    cache=Z

    print(type(Z))
    print(Z)
    A=1/(1+(np.exp((-Z))))

    return A, cache
还有一些相关信息:

  Z=(np.matmul(W,A)+b)
Z的类型是:

  <class 'numpy.ndarray'>
不幸的是,我得到了一个:一元操作数类型错误-:'tuple' 我一直在努力解决这个问题,但运气不好。我很感激任何建议。 最好的

这对我很有效。我认为不需要使用缓存,因为您已经初始化了它。请尝试下面的代码

import matplotlib.pyplot as plt 
import numpy as np 

z = np.linspace(-10, 10, 100) 
def sigmoid(z):
    return 1/(1 + np.exp(-z))

a = sigmoid(z)
plt.plot(z, a) 
plt.xlabel("z") 
plt.ylabel("sigmoid(z)")
这对我有用。我认为不需要使用缓存,因为您已经初始化了它。请尝试下面的代码

import matplotlib.pyplot as plt 
import numpy as np 

z = np.linspace(-10, 10, 100) 
def sigmoid(z):
    return 1/(1 + np.exp(-z))

a = sigmoid(z)
plt.plot(z, a) 
plt.xlabel("z") 
plt.ylabel("sigmoid(z)")

这里的Z显然是一个元组,不是numpy数组,或者其他类似数组的对象。你能提供更多的代码来指示函数中输入了什么吗?这里的Z显然是一个元组,不是numpy数组,或者其他类似数组的对象。你能提供更多的代码来指示函数中输入了什么吗?