cmatrix.Matrix.accumulate

Matrix.accumulate()

Sum accumulator function ruled by mode argument. Realize the cummulated sum depending on direction.

Parameters

Type

Description

mode

int

Switch the mode between :
  • 0 => vectorized horizontal

  • 1 => vectorized vertical

  • 2 => matrix vertical

  • 3 => matrix horizontal

Returns
Matrix

The accumulated matrix

Examples

>>> from matrix import *
>>> t=rand(4)
>>> Print(t)
| +2.000 | +3.000 | +3.000 | +2.000 |
| +5.000 | +6.000 | +0.000 | +15.000 |
| +10.000 | +6.000 | +1.000 | +1.000 |
| +14.000 | +10.000 | +9.000 | +16.000 |
printed
>>> print(t.accumulate(0).data)
[10, 26, 18, 49]
>>> print(t.accumulate(1).data)
[31, 25, 13, 34]
>>> Print(t.accumulate(2))
| +2.000 | +3.000 | +3.000 | +2.000 |
| +7.000 | +9.000 | +3.000 | +17.000 |
| +17.000 | +15.000 | +4.000 | +18.000 |
| +31.000 | +25.000 | +13.000 | +34.000 |
printed
>>> Print(t.accumulate(3))
| +2.000 | +5.000 | +8.000 | +10.000 |
| +5.000 | +11.000 | +11.000 | +26.000 |
| +10.000 | +16.000 | +17.000 | +18.000 |
| +14.000 | +24.000 | +33.000 | +49.000 |
printed