MCPcopy Create free account
hub / github.com/numpy/numpy / hsplit

Function hsplit

numpy/lib/shape_base.py:874–940  ·  view source on GitHub ↗

Split an array into multiple sub-arrays horizontally (column-wise). Please refer to the `split` documentation. `hsplit` is equivalent to `split` with ``axis=1``, the array is always split along the second axis except for 1-D arrays, where it is split at ``axis=0``. See Also

(ary, indices_or_sections)

Source from the content-addressed store, hash-verified

872
873@array_function_dispatch(_hvdsplit_dispatcher)
874def hsplit(ary, indices_or_sections):
875 """
876 Split an array into multiple sub-arrays horizontally (column-wise).
877
878 Please refer to the `split` documentation. `hsplit` is equivalent
879 to `split` with ``axis=1``, the array is always split along the second
880 axis except for 1-D arrays, where it is split at ``axis=0``.
881
882 See Also
883 --------
884 split : Split an array into multiple sub-arrays of equal size.
885
886 Examples
887 --------
888 >>> x = np.arange(16.0).reshape(4, 4)
889 >>> x
890 array([[ 0., 1., 2., 3.],
891 [ 4., 5., 6., 7.],
892 [ 8., 9., 10., 11.],
893 [12., 13., 14., 15.]])
894 >>> np.hsplit(x, 2)
895 [array([[ 0., 1.],
896 [ 4., 5.],
897 [ 8., 9.],
898 [12., 13.]]),
899 array([[ 2., 3.],
900 [ 6., 7.],
901 [10., 11.],
902 [14., 15.]])]
903 >>> np.hsplit(x, np.array([3, 6]))
904 [array([[ 0., 1., 2.],
905 [ 4., 5., 6.],
906 [ 8., 9., 10.],
907 [12., 13., 14.]]),
908 array([[ 3.],
909 [ 7.],
910 [11.],
911 [15.]]),
912 array([], shape=(4, 0), dtype=float64)]
913
914 With a higher dimensional array the split is still along the second axis.
915
916 >>> x = np.arange(8.0).reshape(2, 2, 2)
917 >>> x
918 array([[[0., 1.],
919 [2., 3.]],
920 [[4., 5.],
921 [6., 7.]]])
922 >>> np.hsplit(x, 2)
923 [array([[[0., 1.]],
924 [[4., 5.]]]),
925 array([[[2., 3.]],
926 [[6., 7.]]])]
927
928 With a 1-D array, the split is along axis 0.
929
930 >>> x = np.array([0, 1, 2, 3, 4, 5])
931 >>> np.hsplit(x, 2)

Callers 3

test_0D_arrayMethod · 0.90
test_1D_arrayMethod · 0.90
test_2D_arrayMethod · 0.90

Calls 2

ndimMethod · 0.80
splitFunction · 0.70

Tested by 3

test_0D_arrayMethod · 0.72
test_1D_arrayMethod · 0.72
test_2D_arrayMethod · 0.72