ndarray 1D matrix multiplication #397

Open
opened 2024-04-23 10:31:12 +08:00 by derppening · 0 comments
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 ```
Sign in to join this conversation.
No Milestone
No Assignees
1 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
There is no content yet.