I am using the LSTM tutorial for Theano (http://deeplearning.net/tutorial/lstm.html). In the lstm.py (http://deeplearning.net/tutorial/code/lstm.py) file, I don't understand the following line:
c = m_[:, None] * c + (1. - m_)[:, None] * c_
What does m_[:, None]
mean? In this case m_
is the theano vector while c
is a matrix.
This question has been asked and answered on the Theano mailing list, but is actually about the basics of numpy indexing.
Here are the question and answer https://groups.google.com/forum/#!topic/theano-users/jq92vNtkYUI
For completeness, here is another explanation: slicing with
None
adds an axis to your array, see the relevant numpy documentation, because it behaves the same in both numpy and Theano:http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#numpy.newaxis
Note that
np.newaxis is None
:Typically this is used to adjust shapes to be able to broadcast to higher dimensions. E.g. tiling 7 times in the middle axis can be achieved as
I think the Theano vector's
__getitem__
method expects a tuple as an argument! like this:Here
print a[0,2]
whena
is an ordinary list will raise an exception:But here the
__getitem__
method is different and it accepts a tuple as an argument.You can pass the
:
sign to__getitem__
like this as:
means slice:Speaking about
None
, it can be used when indexing in plain Python as well: