Macaulay2 » Documentation
Packages » Python » PythonObject » PythonObject // PythonObject » PythonObject //= Thing
next | previous | forward | backward | up | index | toc

# PythonObject //= Thing -- augmented floor division of Python objects

- Operator: //=
- Usage:
    `x //= y`
- Inputs:
  - x, a python object,
  - y, a thing,
- Outputs:
  - a python object, the floor quotient of x and y, assigned to x;

## Description

Divide two Python objects, giving the "floor" quotient, e.g., when dividing two integers, the result is the quotient using Euclidean division. Then assign the result to the first argument.

    i1 : x = toPython 5

    o1 = 5

    o1 : PythonObject of class int

    i2 : x //= toPython 3

    o2 = 1

    o2 : PythonObject of class int

    i3 : x

    o3 = 1

    o3 : PythonObject of class int

If the right-hand side is a Macaulay2 object, then it is first converted to a Python object before dividing.

    i4 : x = toPython 12

    o4 = 12

    o4 : PythonObject of class int

    i5 : x //= 5

    o5 = 2

    o5 : PythonObject of class int

    i6 : x

    o6 = 2

    o6 : PythonObject of class int

If the Python class of x defines an `__ifloordiv__` method for in-place floor division, then it will be called. Otherwise, x and y will be divided in the usual way, creating a new Python object that is assigned back to x.

For example, NumPy arrays support in-place floor division. In the example below, x is modified directly, and no new object is created.

    i7 : installNumPyMethods();

    i8 : x = toPython matrix {{5, 6}, {7, 8}}

    o8 = [[1 2]
          [3 4]]

    o8 : PythonObject of class numpy.ndarray

    i9 : x //= matrix {{1, 2}, {3, 4}}

    o9 = [[5 3]
          [2 2]]

    o9 : PythonObject of class numpy.ndarray

    i10 : x

    o10 = [[5 3]
           [2 2]]

    o10 : PythonObject of class numpy.ndarray

## See also

- PythonObject // PythonObject -- floor division of Python objects
- augmented assignment
- installNumPyMethods -- install NumPy methods

## Ways to use this method:

- PythonObject //= Thing -- augmented floor division of Python objects

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