np.triu
np.triu
numpy.triu(m, k=0)
Upper triangle of an array.
Return a copy of a matrix with the elements below the k-th diagonal zeroed.
返回一個矩陣的上三角矩陣,第k條對角線以下的元素歸零
例如:
import numpy as np np.triu(np.ones([4,4]), k=1).astype('uint8')output:
array([[0, 1, 1, 1],[0, 0, 1, 1],[0, 0, 0, 1],[0, 0, 0, 0]], dtype=uint8) import numpy as np np.triu(np.ones([4,4]), k=0).astype('uint8')output:
array([[1, 1, 1, 1],[0, 1, 1, 1],[0, 0, 1, 1],[0, 0, 0, 1]], dtype=uint8)總結
- 上一篇: 搜索智能提示suggestion,附近地
- 下一篇: 44年前的一个数学猜想终被破解