What would be the most efficient way to multiply (element-wise) a 2D tensor (matrix):
x11 x12 .. x1N
...
xM1 xM2 .. xMN
by a vertical vector:
w1
...
wN
to obtain a new matrix:
x11*w1 x12*w2 ... x1N*wN
...
xM1*w1 xM2*w2 ... xMN*wN
To give some con...

Asked By Andrzej Pronobis

What would be the most efficient way to multiply (element-wise) a 2D tensor (matrix):
x11 x12 .. x1N
...
xM1 xM2 .. xMN
by a vertical vector:
w1
...
wN
to obtain a new matrix:
x11*w1 x12*w2 ... x1N*wN
...
xM1*w1 xM2*w2 ... xMN*wN
To give some con...

Asked By Andrzej Pronobis

I am trying to carry out tensor multiplication in NumPy/Tensorflow.
I have 3 tensors- A (M X h), B (h X N X s), C (s X T).
I believe that A X B X C should produce a tensor D (M X N X T).
Here's the code (using both numpy and tensorflow).
M = 5
N = 2
...

Asked By Nipun Batra

I have two matrices
a = np.matrix([[1,2], [3,4]])
b = np.matrix([[5,6], [7,8]])
and I want to get the element-wise product, [[1*5,2*6], [3*7,4*8]], equaling
[[5,12], [21,32]]
I have tried
print(np.dot(a,b))
and
print(a*b)
but both give the r...

Asked By Malintha

The numpy docs recommend using array instead of matrix for working with matrices. However, unlike octave (which I was using till recently), * doesn't perform matrix multiplication, you need to use the function matrixmultipy(). I feel this makes the code v...

Asked By elexhobby

I'm trying to multiply two matrices together using pure python. Input (X1 is a 3x3 and Xt is a 3x2):
X1 = [[1.0016, 0.0, -16.0514],
[0.0, 10000.0, -40000.0],
[-16.0514, -40000.0, 160513.6437]]
Xt = [(1.0, 1.0),
(0.0, 0.25),
...

Asked By Ammar

I have a 2D matrix M of shape [batch x dim], I have a vector V of shape [batch]. How can I multiply each of the columns in the matrix by the corresponding element in the V? That is:
I know an inefficient numpy implementation would look like this:
impo...

Asked By CentAu

This:
import numpy as np
a = np.array([1, 2, 1])
w = np.array([[.5, .6], [.7, .8], [.7, .8]])
print(np.dot(a, w))
# [ 2.6 3. ] # plain nice old matrix multiplication n x (n, m) -> m
import tensorflow as tf
a = tf.constant(a, dtype=tf.float64)
w = ...

Asked By Mr_and_Mrs_D

This:
import numpy as np
a = np.array([1, 2, 1])
w = np.array([[.5, .6], [.7, .8], [.7, .8]])
print(np.dot(a, w))
# [ 2.6 3. ] # plain nice old matrix multiplication n x (n, m) -> m
import tensorflow as tf
a = tf.constant(a, dtype=tf.float64)
w = ...

Asked By Mr_and_Mrs_D