Computes the matrix product. This function is Array API compatible, contrary to :func:`numpy.matmul`. Parameters ---------- x1 : array_like The first input array. x2 : array_like The second input array. Returns ------- out : ndarray
(x1, x2, /)
| 3316 | |
| 3317 | @array_function_dispatch(_matmul_dispatcher) |
| 3318 | def matmul(x1, x2, /): |
| 3319 | """ |
| 3320 | Computes the matrix product. |
| 3321 | |
| 3322 | This function is Array API compatible, contrary to |
| 3323 | :func:`numpy.matmul`. |
| 3324 | |
| 3325 | Parameters |
| 3326 | ---------- |
| 3327 | x1 : array_like |
| 3328 | The first input array. |
| 3329 | x2 : array_like |
| 3330 | The second input array. |
| 3331 | |
| 3332 | Returns |
| 3333 | ------- |
| 3334 | out : ndarray |
| 3335 | The matrix product of the inputs. |
| 3336 | This is a scalar only when both ``x1``, ``x2`` are 1-d vectors. |
| 3337 | |
| 3338 | Raises |
| 3339 | ------ |
| 3340 | ValueError |
| 3341 | If the last dimension of ``x1`` is not the same size as |
| 3342 | the second-to-last dimension of ``x2``. |
| 3343 | |
| 3344 | If a scalar value is passed in. |
| 3345 | |
| 3346 | See Also |
| 3347 | -------- |
| 3348 | numpy.matmul |
| 3349 | |
| 3350 | Examples |
| 3351 | -------- |
| 3352 | For 2-D arrays it is the matrix product: |
| 3353 | |
| 3354 | >>> a = np.array([[1, 0], |
| 3355 | ... [0, 1]]) |
| 3356 | >>> b = np.array([[4, 1], |
| 3357 | ... [2, 2]]) |
| 3358 | >>> np.linalg.matmul(a, b) |
| 3359 | array([[4, 1], |
| 3360 | [2, 2]]) |
| 3361 | |
| 3362 | For 2-D mixed with 1-D, the result is the usual. |
| 3363 | |
| 3364 | >>> a = np.array([[1, 0], |
| 3365 | ... [0, 1]]) |
| 3366 | >>> b = np.array([1, 2]) |
| 3367 | >>> np.linalg.matmul(a, b) |
| 3368 | array([1, 2]) |
| 3369 | >>> np.linalg.matmul(b, a) |
| 3370 | array([1, 2]) |
| 3371 | |
| 3372 | |
| 3373 | Broadcasting is conventional for stacks of arrays |
| 3374 | |
| 3375 | >>> a = np.arange(2 * 2 * 4).reshape((2, 2, 4)) |
no outgoing calls
searching dependent graphs…