Home>

### python - i want to restore the result of calculating the inner product with numpy

There is z that transforms y as a result of dot producting the arrays x and w.
I want to create a program that uses these z and w to return to the original x.
Thank you.

import numpy as np

x = np.array ([[0, 1, 4, 5],
[1, 2, 5, 6],
[2, 3, 6, 7],
[4, 5, 8, 9],
[5, 6, 9, 0],
[6, 7, 0, 1],
[8, 9, 2, 3],
[9, 0, 3, 4],
[0, 1, 4, 5],])
print (x)
w = np.array ([,
,
,
])
print (w.shape)
y = np.dot (x, w)

print (y)
z = y.reshape (1, 3, 3, -1) .transpose (0, 3, 2, 1)
print (z)

How can I write this operation from z to y in numpy?
Do the reverse of y = np.dot (x, w)
I would like to know if there is a function that calculates the inverse of the inner product of y and w.

What I did
y_ = z.transpose (0,2,3,1) .reshape (-1,1)
print (y_)

x_ = np.dot (y_, w_.T)
print (x_)

But x_ did not revert to the original x.

• Answer # 1

Here's a simple example.
Where x1 and x2 are different vectors, but w and the inner product y1 and y2 have the same value.
In other words, in principle, it is not possible to obtain the original vector from the inner product.

``````import numpy as np
x1 = np.array ([1,2])
x2 = np.array ([1,3])
w = np.array ([2,0])
y1 = np.dot (x1, w)
print (y1) #->2
y2 = np.dot (x2, w)
print (y2) #->2``````