【发布时间】:2020-02-14 06:55:11
【问题描述】:
我想创建一个值范围为 0.0 到 1.0 的数组,如下所示: weighting matrix
基本上,左侧和顶部边缘应保持接近 1.0,但在角落处缓慢衰减到 0.5。 底部和右侧边缘应保持接近 0.0 中间区域应该大部分是 0.5,并且值应该从 1.0 到 0.0 对角线衰减。
这是我尝试过的,但它并不能完全满足我的需求。
import numpy as np
import matplotlib.pyplot as plt
def sigmoid(x):
y = np.zeros(len(x))
for i in range(len(x)):
y[i] = 1 / (1 + math.exp(-x[i]))
return y
sigmoid_ = sigmoid(np.linspace(20, 2.5, 30))
temp1 = np.repeat(sigmoid_.reshape((1,len(sigmoid_))), repeats=10, axis=0)
sigmoid_ = sigmoid(np.linspace(6, 3, 10))
temp2 = np.repeat(sigmoid_.reshape((len(sigmoid_),1)), repeats=30, axis=1)
alpha1 = temp1 + temp2
sigmoid_ = sigmoid(np.linspace(-2.5, -20, 30))
temp1 = np.repeat(sigmoid_.reshape((1,len(sigmoid_))), repeats=10, axis=0)
sigmoid_ = sigmoid(np.linspace(-3, -6, 10))
temp2 = np.repeat(sigmoid_.reshape((len(sigmoid_),1)), repeats=30, axis=1)
alpha2 = temp1 + temp2
alpha = alpha1 + alpha2
alpha = alpha - np.min(alpha)
alpha = alpha / np.max(alpha)
plt.matshow(alpha)
这给了我这个:results
有人可以帮我吗?
【问题讨论】:
-
有你想要的数学表示吗?因为有很多方法可以获得模糊的 2D sigmoidal。
-
@user633611 快速和慢速的区别?