好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Pythonnumpy怎么提取矩阵的指定行列

这次给大家带来Python numpy怎么提取矩阵的指定行列,Python numpy提取矩阵指定行列的注意事项有哪些,下面就是实战案例,一起来看一下。

如下所示:

import numpy as np
a=np.arange(9).reshape(3,3) 
a
Out[31]: 
array([[0, 1, 2],
  [3, 4, 5],
  [6, 7, 8]]) 

矩阵的某一行

a[1]
Out[32]: array([3, 4, 5]) 

矩阵的某一列

a[:,1]
Out[33]: array([1, 4, 7]) 
b=np.eye(3,3)
b
Out[36]: 
array([[ 1., 0., 0.],
  [ 0., 1., 0.],
  [ 0., 0., 1.]]) 

把矩阵a的第2列赋值给矩阵b的第1列

b[:,0]=a[:,1]
b
Out[38]: 
array([[ 1., 0., 0.],
  [ 4., 1., 0.],
  [ 7., 0., 1.]]) 

相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!

推荐阅读:

Python怎么实现马氏距离

python怎么批量读取txt文件为DataFrame格式

以上就是Python numpy怎么提取矩阵的指定行列的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于Pythonnumpy怎么提取矩阵的指定行列的详细内容...

  阅读:43次