且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Numpy/Scipy中切片数组

更新时间:2023-02-26 15:45:48

使用a[i,j](不是a[i][j])为二维numpy数组建立索引,但是您可以对numpy数组和矩阵使用相同的切片符号在python中使用普通矩阵(只需将它们放在单个[]中):

Two dimensional numpy arrays are indexed using a[i,j] (not a[i][j]), but you can use the same slicing notation with numpy arrays and matrices as you can with ordinary matrices in python (just put them in a single []):


>>> from numpy import array
>>> a = array([[1,2,3],[3,4,5],[4,5,6]])
>>> a[:,1:]
array([[2, 3],
       [4, 5],
       [5, 6]])