Numpy matrix power/exponent with modulo?

后端 未结 4 1719
慢半拍i
慢半拍i 2021-01-01 21:20

Is it possible to use numpy\'s linalg.matrix_power with a modulo so the elements don\'t grow larger than a certain value?

4条回答
  •  走了就别回头了
    2021-01-01 21:43

    What's wrong with the obvious approach?

    E.g.

    import numpy as np
    
    x = np.arange(100).reshape(10,10)
    y = np.linalg.matrix_power(x, 2) % 50
    

提交回复
热议问题