cmatrix.Matrix.normalize

Matrix.normalize()

Normalize the self matrix. (the sum of each element is equal to 1)

Returns
Matrix

The normalized matrix

Examples

>>> t=gaussian(5,0,0)
>>> Print(t)
| +1.000 | +4.000 | +6.000 | +4.000 | +1.000 |
| +4.000 | +16.000 | +24.000 | +16.000 | +4.000 |
| +6.000 | +24.000 | +36.000 | +24.000 | +6.000 |
| +4.000 | +16.000 | +24.000 | +16.000 | +4.000 |
| +1.000 | +4.000 | +6.000 | +4.000 | +1.000 |
printed
>>> t.normalize()
>>> Print(t)
| +0.004 | +0.016 | +0.023 | +0.016 | +0.004 |
| +0.016 | +0.062 | +0.094 | +0.062 | +0.016 |
| +0.023 | +0.094 | +0.141 | +0.094 | +0.023 |
| +0.016 | +0.062 | +0.094 | +0.062 | +0.016 |
| +0.004 | +0.016 | +0.023 | +0.016 | +0.004 |
printed
>>> sum=0
>>> for i in range(0,5):
...     for j in range(0,5):
...             sum+=t[[i,j]]
...
>>> Print(sum)
1.0