numpy 返回函数的上三角矩阵实例

yipeiwu_com5年前Python基础

numpy 返回函数的上三角矩阵

np.triu()

matrix2=np.triu(matrix1)

numpy.triu(m, k=0)[source]

Upper triangle of an array.

Return a copy of a matrix with the elements below the k-th diagonal zeroed.

np.triu([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], -1)
array([[ 1, 2, 3],
[ 4, 5, 6],
[ 0, 8, 9],
[ 0, 0, 12]])

以上这篇numpy 返回函数的上三角矩阵实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python中的编码知识整理汇总

问题 在平时工作中,遇到了这样的错误: UnicodeDecodeError: 'ascii' codec can't decode byte 想必大家也都碰到过,很常见 。于是...

Django model update的多种用法介绍

Django model update的多种用法介绍

model update常规用法 假如我们的表结构是这样的 class User(models.Model): username = models.CharField(max_le...

浅谈Python中列表生成式和生成器的区别

列表生成式语法: [x*x for x in range(0,10)] //列表生成式,这里是中括号 //结果 [0, 1, 4, 9, 16, 25, 36, 49, 64, 81...

python 普通克里金(Kriging)法的实现

python 普通克里金(Kriging)法的实现

克里金法时一种用于空间插值的地学统计方法。 克里金法用半变异测定空间要素,要素即自相关要素。 半变异公式为: 其中γ(h) 是已知点 xi 和 xj 的半变异,***h***表示...

Python模拟鼠标点击实现方法(将通过实例自动化模拟在360浏览器中自动搜索python)

Python模拟鼠标点击实现方法(将通过实例自动化模拟在360浏览器中自动搜索python)

一、准备工作: 安装pywin32,后面开发需要pywin32的支持,否则无法完成与windows层面相关的操作。 pywin32的具体安装及注意事项: 1、整体开发环境: 基于wind...