博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python 下三角矩阵_Python | 矩阵的上三角
阅读量:2530 次
发布时间:2019-05-11

本文共 1453 字,大约阅读时间需要 4 分钟。

python 下三角矩阵

A matrix can be seen in different ways and one of them is the upper triangular matrix part. Some problems in linear algebra are concerned with the upper triangular part of the matrix.

可以用不同的方式看到矩阵,其中之一是上三角矩阵部分。 线性代数中的一些问题与矩阵的上三角部分有关。

For this purpose, we have a predefined function numpy.triu(a) in the NumPy library package which automatically stores the upper triangular elements in a separate matrix. In this article, we are going to print the upper triangular elements of a matrix using inbuilt function numpy.triu(a).

为此,我们在NumPy库包中有一个预定义的函数numpy.triu(a) ,该函数自动将上三角元素存储在单独的矩阵中。 在本文中,我们将使用内置函数numpy.triu(a)打印矩阵的上三角元素

Python代码查找矩阵的上三角 (Python code to find upper triangle of a matrix)

# Linear Algebra Learning Sequence# Upper Triangle of matriximport numpy as npprint('Upper Triangle of an 3x3 identity matrix : ', np.triu(np.eye(3)))a = np.arange(9).reshape((3,3))print('\n\nMatrix a :\n', a)print('Upper Triangle of Matrix a :\n', np.triu(a))b = np.triu(np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]]))print('\n\nMatrix b :\n', np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]]))print('Upper Triangle of Matrix b : ', b)

Output:

输出:

Upper Triangle of an 3x3 identity matrix :  [[1. 0. 0.] [0. 1. 0.] [0. 0. 1.]]Matrix a : [[0 1 2] [3 4 5] [6 7 8]]Upper Triangle of Matrix a : [[0 1 2] [0 4 5] [0 0 8]]Matrix b : [[ 1  2  3] [ 4  5  6] [ 7  8  9] [10 11 12]]Upper Triangle of Matrix b :  [[1 2 3] [0 5 6] [0 0 9] [0 0 0]]

翻译自:

python 下三角矩阵

转载地址:http://iapzd.baihongyu.com/

你可能感兴趣的文章
java学习笔记④MySql数据库--01/02 database table 数据的增删改
查看>>
两台电脑如何实现共享文件
查看>>
组合模式Composite
查看>>
程序员最想得到的十大证件,你最想得到哪个?
查看>>
我的第一篇CBBLOGS博客
查看>>
【MyBean调试笔记】接口的使用和清理
查看>>
07 js自定义函数
查看>>
jQueru中数据交换格式XML和JSON对比
查看>>
form表单序列化后的数据转json对象
查看>>
[PYTHON]一个简单的单元測试框架
查看>>
iOS开发网络篇—XML数据的解析
查看>>
[BZOJ4303]数列
查看>>
一般处理程序在VS2012中打开问题
查看>>
C语言中的++和--
查看>>
thinkphp3.2.3入口文件详解
查看>>
POJ 1141 Brackets Sequence
查看>>
Ubuntu 18.04 root 使用ssh密钥远程登陆
查看>>
Servlet和JSP的异同。
查看>>
虚拟机centOs Linux与Windows之间的文件传输
查看>>
ethereum(以太坊)(二)--合约中属性和行为的访问权限
查看>>