  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # theano ~ use an index matrix and embeddings matrix to produce a 3D tensor?

## theano ~ use an index matrix and embeddings matrix to produce a 3D tensor? Tag : python , By : markku Date : November 24 2020, 09:00 AM

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 .

## Indexing tensor with index matrix in theano?

Tag : python , By : gcomstock
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 one-line 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)[:, np.newaxis], np.arange(A.shape), B]
``````
``````import theano
import theano.tensor as T

AA = T.tensor3()
BB = T.imatrix()

CC = AA[T.arange(AA.shape).reshape((-1, 1)), T.arange(AA.shape), BB]

f = theano.function([AA, BB], CC)

f(A.astype(theano.config.floatX), B)
``````

## Theano matrix multiplication of 2d matrix to give 3d matrix

Tag : python , By : Shane
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
``````# Get mask of matching elements against the iterators
m,n = I.shape

# Get the mask of intersecting ones

# Get D intersection masked array

# 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 : 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 : out
Out:
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?

Tag : development , By : Tony Z
Date : March 29 2020, 07:55 AM
should help you out As of today, the behavior of accessing out-of-range 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).
Godbolt-Demo: https://godbolt.org/z/RrnjXS 