it should still fix some issue Let's say I have an index matrix: , You can simply index into the embedding matrix with the index matrix: import numpy
import theano
import theano.tensor as tt
embeddings_matrix = theano.shared(numpy.array([[1, 2, 3], [2, 3, 4], [4, 5, 6]], dtype=theano.config.floatX))
index_matrix = tt.imatrix()
y = embeddings_matrix[index_matrix]
f = theano.function([index_matrix], y)
output = f(numpy.array([[0, 1], [2, 1]], dtype=numpy.int32))
print output.shape, '\n', output
(2L, 2L, 3L)
[[[ 1. 2. 3.]
[ 2. 3. 4.]]
[[ 4. 5. 6.]
[ 2. 3. 4.]]]
Boards Message : 
You Must Login
Or Sign Up
to Add Your Comments . 
Share :

Indexing tensor with index matrix in theano?
Date : March 29 2020, 07:55 AM
This might help you I have a theano tensor A such that A.shape = (40, 20, 5) and a theano matrix B such that B.shape = (40, 20). Is there a oneline operation I can perform to get a matrix C, where C.shape = (40, 20) and C(i,j) = A[i, j, B[i,j]] with theano syntax? , You can do the following in numpy: import numpy as np
A = np.arange(4 * 2 * 5).reshape(4, 2, 5)
B = np.arange(4 * 2).reshape(4, 2) % 5
C = A[np.arange(A.shape[0])[:, np.newaxis], np.arange(A.shape[1]), B]
import theano
import theano.tensor as T
AA = T.tensor3()
BB = T.imatrix()
CC = AA[T.arange(AA.shape[0]).reshape((1, 1)), T.arange(AA.shape[1]), BB]
f = theano.function([AA, BB], CC)
f(A.astype(theano.config.floatX), B)

Theano matrix multiplication of 2d matrix to give 3d matrix
Date : March 29 2020, 07:55 AM
To fix this issue I want to do exactly what the following question is trying to do in numpy: , As per @Divakar s comment, change it to x[:,:,None] * y[:,None,:]

How to use integer values of a matrix as index for another matrix using numpy or Theano?
Tag : python , By : user184975
Date : March 29 2020, 07:55 AM
may help you . Here's a vectorized approach using broadcasting  # Get mask of matching elements against the iterators
m,n = I.shape
Imask = I == np.arange(m)[:,None,None,None]
Jmask = J == np.arange(n)[:,None,None]
# Get the mask of intersecting ones
mask = Imask & Jmask
# Get D intersection masked array
Dvals = np.where(mask,D,np.inf)
# Get argmin along merged last two axes. Index into flattened V for final o/p
out = V.ravel()[Dvals.reshape(m,n,1).argmin(1)]
In [136]: I = np.array([[0,1,2],[1,1,0],[0,0,2]])
...: J = np.array([[1,1,1],[1,2,1],[0,1,0]])
...: D = np.array([[1.2, 3.4, 2.2],[2.2, 4.3, 2.3],[7.1, 6.1, 2.7]])
...: V = np.array([[1.1 , 8.1, 9.1],[3.1, 7.1, 2.1],[0.1, 5.1, 3.1]])
...:
In [144]: out
Out[144]:
array([[ 0.1, 1.1, 1.1], # To verify : v[0,1] = 1.1
[ 1.1, 3.1, 7.1],
[ 3.1, 9.1, 1.1]])

How to understand a theano tensor as a matrix and a keras.backend variable?
Tag : python , By : Keonne Rodriguez
Date : March 29 2020, 07:55 AM
like below fixes the issue According to the source code, keras creates this in theano: variable = theano.shared(value=np.zeros(shape),
name='somename',
strict=False)
variable._keras_shape = value.shape
variable._uses_learning_phase = False

Why the first index of a multidimensional matrix of Eigen::Tensor able to loop through all the members of the tensor?
Date : March 29 2020, 07:55 AM
should help you out As of today, the behavior of accessing outofrange elements of an Eigen::Tensor is not documented. But you can actually have it generate assertions when compiling with DEIGEN_INTERNAL_DEBUGGING (however, this can make execution significantly slower). GodboltDemo: https://godbolt.org/z/RrnjXS

