Skip to content

Commit

Permalink
add array_split
Browse files Browse the repository at this point in the history
  • Loading branch information
llinjupt committed Apr 8, 2019
1 parent 0b6508d commit ea3da92
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions numpy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,25 @@ split() 可以指定用于分割的轴,其余参数与 vsplit() 和 hsplit()
[10 11]
[14 15]]
非均匀分割
`````````````````

split 函数只能进行均匀分割,例如上例中 A 有 4 行,那么分为 3 个数组就会报异常,此时可以使用 array_split,它不是均分,它尝试把多余部分依次塞入子数组中。

.. code-block:: python
:linenos:
:lineno-start: 0
subs = np.split(A, 3, array_split=1) # 非均匀分割
for i in subs:
print(i)
>>>
[[0 1 2 3]
[4 5 6 7]] # 第一个子数组行数为 2
[[ 8 9 10 11]]
[[12 13 14 15]]
数组运算
--------------

Expand Down

0 comments on commit ea3da92

Please sign in to comment.