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

yipeiwu_com6年前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之读取TXT文件的方法小结

方法一: <span style="font-size:14px;">#read txt method one f = open("./image/abc.txt")...

Python自定义一个类实现字典dict功能的方法

如下所示: import collections class Mydict(collections.UserDict): def __missing__(self, ke...

通过Pandas读取大文件的实例

当数据文件过大时,由于计算机内存有限,需要对大文件进行分块读取: import pandas as pd f = open('E:/学习相关/Python/数据样例/用户侧数据/te...

pandas 对series和dataframe进行排序的实例

本问主要写根据索引或者值对series和dataframe进行排序的实例讲解 代码: #coding=utf-8 import pandas as pd import numpy a...

Python实现读取SQLServer数据并插入到MongoDB数据库的方法示例

本文实例讲述了Python实现读取SQLServer数据并插入到MongoDB数据库的方法。分享给大家供大家参考,具体如下: # -*- coding: utf-8 -*- impo...