jax.numpy.split#
- jax.numpy.split(ary, indices_or_sections, axis=0)[source]#
将数组分割成子数组。
JAX 实现的
numpy.split()
。- 参数:
- 返回:
数组列表。如果
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