__matmul__¶
- array.__matmul__(other: array, /) array ¶
Computes the matrix product.
Note
The
matmul
function must implement the same semantics as the built-in@
operator (see PEP 465).- Parameters:
self (array) – array instance. Should have a numeric data type. Must have at least one dimension. If
self
is one-dimensional having shape(M,)
andother
has more than one dimension,self
must be promoted to a two-dimensional array by prepending1
to its dimensions (i.e., must have shape(1, M)
). After matrix multiplication, the prepended dimensions in the returned array must be removed. Ifself
has more than one dimension (including after vector-to-matrix promotion),shape(self)[:-2]
must be compatible withshape(other)[:-2]
(after vector-to-matrix promotion) (see Broadcasting). Ifself
has shape(..., M, K)
, the innermost two dimensions form matrices on which to perform matrix multiplication.other (array) – other array. Should have a numeric data type. Must have at least one dimension. If
other
is one-dimensional having shape(N,)
andself
has more than one dimension,other
must be promoted to a two-dimensional array by appending1
to its dimensions (i.e., must have shape(N, 1)
). After matrix multiplication, the appended dimensions in the returned array must be removed. Ifother
has more than one dimension (including after vector-to-matrix promotion),shape(other)[:-2]
must be compatible withshape(self)[:-2]
(after vector-to-matrix promotion) (see Broadcasting). Ifother
has shape(..., K, N)
, the innermost two dimensions form matrices on which to perform matrix multiplication.
Note
If either
x1
orx2
has a complex floating-point data type, neither argument must be complex-conjugated or transposed. If conjugation and/or transposition is desired, these operations should be explicitly performed prior to computing the matrix product.- Returns:
out (array) –
if both
self
andother
are one-dimensional arrays having shape(N,)
, a zero-dimensional array containing the inner product as its only element.if
self
is a two-dimensional array having shape(M, K)
andother
is a two-dimensional array having shape(K, N)
, a two-dimensional array containing the conventional matrix product and having shape(M, N)
.if
self
is a one-dimensional array having shape(K,)
andother
is an array having shape(..., K, N)
, an array having shape(..., N)
(i.e., prepended dimensions during vector-to-matrix promotion must be removed) and containing the conventional matrix product.if
self
is an array having shape(..., M, K)
andother
is a one-dimensional array having shape(K,)
, an array having shape(..., M)
(i.e., appended dimensions during vector-to-matrix promotion must be removed) and containing the conventional matrix product.if
self
is a two-dimensional array having shape(M, K)
andother
is an array having shape(..., K, N)
, an array having shape(..., M, N)
and containing the conventional matrix product for each stacked matrix.if
self
is an array having shape(..., M, K)
andother
is a two-dimensional array having shape(K, N)
, an array having shape(..., M, N)
and containing the conventional matrix product for each stacked matrix.if either
self
orother
has more than two dimensions, an array having a shape determined by Broadcastingshape(self)[:-2]
againstshape(other)[:-2]
and containing the conventional matrix product for each stacked matrix.The returned array must have a data type determined by Type Promotion Rules.
Notes
Note
Results must equal the results returned by the equivalent function
matmul()
.Raises
if either
self
orother
is a zero-dimensional array.if
self
is a one-dimensional array having shape(K,)
,other
is a one-dimensional array having shape(L,)
, andK != L
.if
self
is a one-dimensional array having shape(K,)
,other
is an array having shape(..., L, N)
, andK != L
.if
self
is an array having shape(..., M, K)
,other
is a one-dimensional array having shape(L,)
, andK != L
.if
self
is an array having shape(..., M, K)
,other
is an array having shape(..., L, N)
, andK != L
.
Changed in version 2022.12: Added complex data type support.