box% python
Python 3.8.6 (default, Sep 30 2020, 04:00:38)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> e_0 = np.array([1,0,0,0])
>>> e_1 = np.array([0,1,0,0])
>>> e_2 = np.array([0,0,1,0])
>>> e_3 = np.array([0,0,0,1])
>>> np.einsum('a,b->ab', e_0, e_1)
array([[0, 1, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]])
>>> np.einsum('a,b,c->abc', e_0, e_1, e_2)
array([[[0, 0, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]],
[[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]],
[[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]],
[[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]])
>>>
Comments
0 B
|👍
/👎