Macaulay2 » Documentation
Packages » Python » PythonObject » PythonObject @ PythonObject
next | previous | forward | backward | up | index | toc

# PythonObject @ PythonObject -- matrix multiplication of Python objects

- Operator: @
- Usage:
    `x @ y`
- Inputs:
  - x, a python object,
  - y, a python object,
- Outputs:
  - a python object, the product of x and y as matrices;

## Description

Multiply two Python objects (e.g., NumPy arrays) as matrices.

    i1 : installNumPyMethods();

    i2 : a = toPython matrix {{1, 0}, {0, 1}}

    o2 = [[1 0]
          [0 1]]

    o2 : PythonObject of class numpy.ndarray

    i3 : b = toPython matrix {{4, 1}, {2, 2}}

    o3 = [[4 1]
          [2 2]]

    o3 : PythonObject of class numpy.ndarray

    i4 : a @ b

    o4 = [[4 1]
          [2 2]]

    o4 : PythonObject of class numpy.ndarray

In Macaulay2, the `*` operator is used for matrix multiplication, but in NumPy, this results in componentwise multiplication.

    i5 : a * b

    o5 = [[4 0]
          [0 2]]

    o5 : PythonObject of class numpy.ndarray

## See also

- PythonObject * PythonObject -- multiply Python objects
- PythonObject @= Thing -- augmented matrix multiplication of Python objects
- installNumPyMethods -- install NumPy methods

### Menu

- PythonObject @= Thing -- augmented matrix multiplication of Python objects

## Ways to use this method:

- PythonObject @ PythonObject -- matrix multiplication of Python objects
- `PythonObject @ Thing`
- `Thing @ PythonObject`

The source of this document is in /build/macaulay2-88fgJW/macaulay2-1.25.11+ds/M2/Macaulay2/packages/Python/doc/arithmetic.m2:297:0.