Theano and NumPy support the basic subscript method and the advanced subscript value method.
The Boolean type of masks is not supported because there is no Boolean type in Theano.
# Head file Supportimport NumPy as NP
Advanced Indexing in NumPy:
The advanced subscript value is used to get the elements in a non-tuple sequence object, typically a bdarray structure.
Commonly available methods of fetching are: Integer and Boolean
>>> x = Np.array ([[1, 2], [3, 4], [5, 6]]) >>> x[[0, 1, 2], [0, 1, 0]]array ([1, 4, 5])
>>> x = Np.array ([1., -1., -2., 3]) >>> x[x < 0] + = 20>>> Xarray ([ 1., 18.,< C8/>3.])
NumPy The Mask operation:
>>> n = np.arange (9). Reshape (3,3) >>> n[n > 4] # Maskarray ([5, 6, 7, 8])
Theano in mask operation:
>>> t = Theano.tensor.arange (9). Reshape ((3,3)) >>> t[t > 4].eval () # An array with shape (3, 3, 3) Array ([[[[0], 1, 2], [0, 1, 2], [0, 1, 2], [[0, 1, 2], [0, 1, 2], [ 3, 4, 5]], [[3, 4, 5], [3, 4 , 5], [3, 4, 5]], dtype=int8)
Thenao tutorial–indexing