python 对角线矩阵_Python | 矩阵的对角线

python 对角线矩阵

Some problems in linear algebra are mainly concerned with diagonal elements of the matrix. For this purpose, we have a predefined function numpy.diag(a) in NumPy library package which automatically stores diagonal elements in an array (a Vector). In this article, we are going to print the diagonal elements of a matrix using inbuilt function numpy.diag(a).

线性代数中的一些问题主要与矩阵的对角线元素有关。 为此,我们在NumPy库包中提供了预定义的函数numpy.diag(a),该函数自动将对角线元素存储在数组(向量)中。 在本文中,我们将使用内置函数numpy.diag(a)打印矩阵的对角线元素。

Python代码查找矩阵的对角线 (Python code to find diagonal of a matrix)

# Linear Algebra Learning Sequence
# Diagonal of matrix

import numpy as np

print('Diagonal of an 3x3 identity matrix : ', np.diag(np.eye(3)))

a = np.arange(9
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值