When I have a tensor and a matrix below:
A = np.array([[['a', 'b'], ['c', 'd']], [['e', 'f'], ['g','h']]], dtype=object)
x = np.array([[1, 2], [3, 4]])
How to generate a tensor shown below?
array([[['abb' 'eff'],
['cdd' 'ghh']],
[['aaabbbb' 'eeeffff'],
['cccdddd' 'ggghhhh']]]
I examined np.tensordot(A, x, 1) and A@x with .transpose(,,), but they looked other forms.
CodePudding user response:
You just need to keep transposing!
>>> (A @ x.T).T
array([[['abb', 'eff'],
['cdd', 'ghh']],
[['aaabbbb', 'eeeffff'],
['cccdddd', 'ggghhhh']]], dtype=object)
