Make special diagonal matrix in Numpy

前端 未结 5 1336
时光取名叫无心
时光取名叫无心 2020-12-06 01:09

I am trying to make a numpy array that looks like this:

[a b c       ]
[  a b c     ]
[    a b c   ]
[      a b c ] 

So this involves updat

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 01:53

    This is an example of a Toeplitz matrix - you can construct it using scipy.linalg.toeplitz:

    import numpy as np
    from scipy.linalg import toeplitz
    
    first_row = np.array([1, 2, 3, 0, 0, 0])
    first_col = np.array([1, 0, 0, 0])
    
    print(toeplitz(first_col, first_row))
    # [[1 2 3 0 0 0]
    #  [0 1 2 3 0 0]
    #  [0 0 1 2 3 0]
    #  [0 0 0 1 2 3]]
    

提交回复
热议问题