MCPcopy Index your code
hub / github.com/numpy/numpy / hsplit

Function hsplit

numpy/lib/_shape_base_impl.py:864–931  ·  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

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

Callers 3

test_0D_arrayMethod · 0.90
test_1D_arrayMethod · 0.90
test_2D_arrayMethod · 0.90

Calls 1

splitFunction · 0.85

Tested by 3

test_0D_arrayMethod · 0.72
test_1D_arrayMethod · 0.72
test_2D_arrayMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…