Numpy中矩阵的不均等分割

网上看到很多有关分割矩阵的方法,多半用到

np.split()
np.vsplit()
np.hsplit()

这些函数实现均等分割,如何实现不均等分割?
想起了Matlab中常用的切片操作[:,:]

>>> RTmat
matrix([[1, 4, 5, 1],
        [2, 8, 7, 1],
        [3, 6, 9, 1]])

>>> RTmat[:,:3]
matrix([[1, 4, 5],
        [2, 8, 7],
        [3, 6, 9]])

>>> RTmat[:,3]
matrix([[1],
        [1],
        [1]])

成功将3x4 mat分割为3x3 mat和3x1 mat

注意:
如果对array而非matrix切片,当列数为1时会自动变为行向量,不保留原形状。

>>> RT
array([[1, 4, 5, 1],
       [2, 8, 7, 1],
       [3, 6, 9, 1]])

>>> RT[:,:3]
array([[1, 4, 5],
       [2, 8, 7],
       [3, 6, 9]])

>>> RT[:,3]
array([1, 1, 1])
原文地址:https://www.cnblogs.com/azureology/p/13096565.html