numpy - 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, 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)")
推荐阅读
- c# - 调用 Dapper 查询
有时会崩溃 - c++ - 如何使我的向量增长到最初未知的大小?
- mysql - SQL查询的结果给出了奇怪的结果
- azure - Azure Cloud 在版本“secrets-store.csi.k8s.io/v1alpha1”中没有匹配类型“SecretProviderClass”
- react-native - React Navigation:单击底部选项卡导航器时打开抽屉
- jenkins - 使用 eachFileRecurse 递归列出 Groovy 中的所有文件返回 FileNotFoundException
- python - 是否可以使用正则表达式通过两个单独的列表值进行搜索并将它们的值存储到两个单独的列表中?
- google-bigquery - BigQuery SQL 中的梯形图函数
- angular - Angular 无法获取查询参数
- python - 为什么 Visual Studio 代码在安装后找不到 pandas