numpy矩阵分割

numpy矩阵分割
本文是课程笔记,课程来源:【莫烦Python】Numpy & Pandas (数据处理教程)

import numpy as np

# 此部分为numpy中矩阵分割操作
array = np.arange(0, 16)
array2d = np.arange(3, 15).reshape(3, 4)

# indices_or_sections参数决定分成多少块,axis决定按哪一个维度进行等量分割
print(array2d)
print(np.split(array2d, indices_or_sections=2, axis=1))
print(np.split(array.reshape(4, 4), indices_or_sections=2, axis=1))

# split仅支持等项分割,对于不等项分割,使用array_split
print(np.array_split(array2d, indices_or_sections=2, axis=0))

# 横向分割
print(np.vsplit(array2d, 3))

# 纵向分割
print(np.hsplit(array2d, 2))

猜你喜欢

转载自blog.csdn.net/Elm_Forest/article/details/124543216