1
votes

I am trying to find the dot product between a scipy sparse matrix and a numpy.ndarray. tensor refers to theano.tensor. X is the sparse matrix and W_hidden is the ndarray. b_hidden is also ndarray.

 tensor.tanh(tensor.dot(X,self.W_hidden)+self.b_hidden)

However, there are several problems with this line. I cant compute the dot product. Apart from that, it seems like I am not able to add a constant ndarray to a sparse matrix and further more, I cant apply the tanh function. The error that I get is:

 TypeError("Cannot convert %s to TensorType" % str_x, type(x))

any help as to how I can solve this problem is highly appreciated.

1
Can you give some details on what exactly your objects look like? Also, could you separate the dot operation, the addition, and the tanh operation to better drill down on the error? - jdotjdot
w_hidden is a 2 dimensional numpy matrix filled with random numbers. X is only 1 dimensional. It is one row and about 10,000 columns. I have also tried separating the computations. The error ralated to the dot product is the type Error. The error related to addition is that you cant add a constant to a sparse matrix, which does not make much sense to me. - BBB

1 Answers

0
votes

I came across same two problem as yours recently though I was not dealing with any tensor quantities. If you are still looking for some help:

1) make W_hidden and b_hidden as numpy matrices instead of ndarray. For example, if b_hidden is of shape, (n,) then its matrix form would be of shape, (n,1). This would allow it be added to another matrix, whether sparse or not.

2) use * instead of dot as both X and W_hidden are matrices. Btw, what is the shape of W_hidden?