我是机器学习的新手,我正在关注tensorflow的教程,创建一些简单的神经网络来学习MNIST数据.
我建立了一个单层网络(遵循tutotial),准确度约为0.92,这对我来说还可以.但后来又添加了一层,精度降低到0.113,这非常糟糕.
以下是2层之间的关系:
import tensorflow as tf
x = tf.placeholder(tf.float32, [None, 784])
#layer 1
W1 = tf.Variable(tf.zeros([784, 100]))
b1 = tf.Variable(tf.zeros([100]))
y1 = tf.nn.softmax(tf.matmul(x, W1) + b1)
#layer 2
W2 = tf.Variable(tf.zeros([100, 10]))
b2 = tf.Variable(tf.zeros([10]))
y2 = tf.nn.softmax(tf.matmul(y1, W2) + b2)
#output
y = y2
y_ = tf.placeholder(tf.float32, [None, 10])
Run Code Online (Sandbox Code Playgroud)
我的结构好吗?导致它表现如此糟糕的原因是什么?我该如何修改我的网络?
我有一个(大)数据数组和(一些)索引列表的(大)列表,例如,
data = [1.0, 10.0, 100.0]
contribs = [[1, 2], [0], [0, 1]]
Run Code Online (Sandbox Code Playgroud)
对于每个条目contribs
,我想总结相应的值data
并将它们放入一个数组中.对于上面的例子,预期的结果是
out = [110.0, 1.0, 11.0]
Run Code Online (Sandbox Code Playgroud)
在循环中执行此操作,
c = numpy.zeros(len(contribs))
for k, indices in enumerate(contribs):
for idx in indices:
c[k] += data[idx]
Run Code Online (Sandbox Code Playgroud)
但由于data
而且contribs
规模很大,所以需要太长时间.
我觉得使用numpy的花式索引可以改善这一点.
任何提示?
我有3个numpy数组A
,B
和C
.为简单起见,我们假设它们都很好[n, n]
.我想将它们安排为块矩阵
A B
B^t C
Run Code Online (Sandbox Code Playgroud)
在哪里B^t
表示的转置B
.当然,我可以通过一系列连接来做到这一点
top_row = np.concatenate([A, B], axis=1)
bottom_row = np.concatenate([B.transpose(), C], axis=1)
result = np.concatenate([top_row, bottom_row], axis=0)
Run Code Online (Sandbox Code Playgroud)
有更简单,更易读的方式吗?