ndarray 1D matrix multiplication #397

Open
opened 2024-04-23 10:31:12 +08:00 by derppening · 1 comment
Collaborator

The behavior depends on the arguments in the following way.

...

  • If the first argument is 1-D, it is promoted to a matrix by prepending a 1 to its dimensions. After matrix multiplication the prepended 1 is removed.

  • If the second argument is 1-D, it is promoted to a matrix by appending a 1 to its dimensions. After matrix multiplication the appended 1 is removed.

>>> np.identity(2) @ np.zeros((2))
array([0., 0.])
>>> np.zeros((2)) @ np.identity(2)
array([0., 0.])
>>> np.zeros((2)) @ np.zeros(2)
0.0
> The behavior depends on the arguments in the following way. > > ... > > - If the first argument is 1-D, it is promoted to a matrix by prepending a 1 to its dimensions. After matrix multiplication the prepended 1 is removed. > > - If the second argument is 1-D, it is promoted to a matrix by appending a 1 to its dimensions. After matrix multiplication the appended 1 is removed. ```py >>> np.identity(2) @ np.zeros((2)) array([0., 0.]) >>> np.zeros((2)) @ np.identity(2) array([0., 0.]) >>> np.zeros((2)) @ np.zeros(2) 0.0 ```
lyken self-assigned this 2024-08-07 16:46:52 +08:00
Collaborator

Implemented in ndstrides, for general N-D tensors.

Implemented in `ndstrides`, for general N-D tensors.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#397
No description provided.