jax.numpy.split#
- jax.numpy.split(ary, indices_or_sections, axis=0)[原始碼]#
將陣列分割成子陣列。
numpy.split()
的 JAX 實作。- 參數:
- 返回:
陣列列表。如果
indices_or_sections
是整數 N,則列表長度為 N。如果indices_or_sections
是序列 seq,則列表長度為 len(seq) + 1。- 返回類型:
範例
分割一維陣列
>>> x = jnp.array([1, 2, 3, 4, 5, 6, 7, 8, 9])
分割成三個相等的部分
>>> chunks = jnp.split(x, 3) >>> print(*chunks) [1 2 3] [4 5 6] [7 8 9]
依索引分割成多個部分
>>> chunks = jnp.split(x, [2, 7]) # [x[0:2], x[2:7], x[7:]] >>> print(*chunks) [1 2] [3 4 5 6 7] [8 9]
沿著軸 1 分割二維陣列
>>> x = jnp.array([[1, 2, 3, 4], ... [5, 6, 7, 8]]) >>> x1, x2 = jnp.split(x, 2, axis=1) >>> print(x1) [[1 2] [5 6]] >>> print(x2) [[3 4] [7 8]]
另請參閱
jax.numpy.array_split()
:類似split
,但允許indices_or_sections
為無法整除陣列大小的整數。jax.numpy.vsplit()
:垂直分割,即沿著 axis=0jax.numpy.hsplit()
:水平分割,即沿著 axis=1jax.numpy.dsplit()
:深度分割,即沿著 axis=2