Skip to content Skip to sidebar Skip to footer

Numpy: Convert An Array To A Triangular Matrix

I was looking for a built in method to convert an linear array to triangular matrix. As I failed in find one I am asking for help in implementing one. Imagine an array like: In [2

Solution 1:

>>> tri = np.zeros((67, 67))
>>> tri[np.triu_indices(67, 1)] = dm

See doc for triu_indices for details. To get a lower-triangular matrix, use np.tril_indices and set the offset to -1 instead of 1.


Post a Comment for "Numpy: Convert An Array To A Triangular Matrix"