# -*- coding: utf-8 -*-
"""
Created on Tue May 21 14:50:04 2019
@author: User
"""
import numpy as np
a = np.arange(9).reshape(3, 3)
print(a)
ahs = np.hsplit(a, 3)
print(ahs)
print(type(ahs))
print(ahs[1])
print('split函数可以实现同样的功能:')
b = np.arange(9).reshape(3, 3)
print(b)
print(np.split(b, 3, axis=1))
print('垂直分拆:')
print(np.vsplit(b, 3))
print(np.split(a, 3, axis = 0))
ads = np.arange(12)
ads.shape = (2,2,3)
print(ads)
print('\n对ads深度分拆:')
print(np.dsplit(ads, 3))
运行:
[[0 1 2]
[3 4 5]
[6 7 8]]
[array([[0],
[3],
[6]]), array([[1],
[4],
[7]]), array([[2],
[5],
[8]])]
[[1]
[4]
[7]]
split函数可以实现同样的功能:
[[0 1 2]
[3 4 5]
[6 7 8]]
[array([[0],
[3],
[6]]), array([[1],
[4],
[7]]), array([[2],
[5],
[8]])]
垂直分拆:
[array([[0, 1, 2]]), array([[3, 4, 5]]), array([[6, 7, 8]])]
[array([[0, 1, 2]]), array([[3, 4, 5]]), array([[6, 7, 8]])]
[[[ 0 1 2]
[ 3 4 5]]
[[ 6 7 8]
[ 9 10 11]]]
对ads深度分拆:
[array([[[0],
[3]],
[[6],
[9]]]), array([[[ 1],
[ 4]],
[[ 7],
[10]]]), array([[[ 2],
[ 5]],
[[ 8],
[11]]])]