多层感知机的实现问题

import gluonbook as gb
from mxnet import nd
from mxnet.gluon import loss as gloss
from numpy import tanh
from scipy.special import expit as sigmoid

num_inputs, num_outputs, num_hiddens = 3, 2, 2

Wh = nd.random.normal(scale=0.01, shape=(num_inputs, num_hiddens))
Bh = nd.zeros(num_hiddens)
Wo = nd.random.normal(scale=0.01, shape=(num_hiddens, num_outputs))
Bo = nd.zeros(num_outputs)

X = nd.array([[2, 4, 3]])
X = X.reshape((-1, num_inputs))

H = tanh(nd.dot(X, Wh) + Bh)
O = sigmoid(nd.dot(H, Wo) + Bo)

错误输出

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-34-cc4959d91629> in <module>()
      9 X = X.reshape((-1, num_inputs))
     10 H = tanh(nd.dot(X, Wh) + Bh)
---> 11 O = sigmoid(nd.dot(H, Wo) + Bo)

~/anaconda2/envs/gluon/lib/python3.6/site-packages/mxnet/ndarray/register.py in dot(lhs, rhs, transpose_a, transpose_b, out, name, **kwargs)

AssertionError: Argument lhs must have NDArray type, but got [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
[-0.05644596]
<NDArray 1 @cpu(0)>]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

  [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
[0.12665378]
<NDArray 1 @cpu(0)>]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

我看 H 没有经过 tanh 函数的时候没问题,是 (1, 2) 的形状。不知道这个是什么问题?谢谢您。

2赞

请问解决了吗?我也遇到了类似的问题,怎么解决,谢谢