8
votes

Python Numpy Split Tableau dans des banquiers inégaux

J'essaie de diviser un tableau en n parties. Parfois, ces parties sont de la même taille, parfois elles sont d'une taille différente.

J'essaie d'utiliser: P>

split = np.split(list, size)


0 commentaires

3 Réponses :


3
votes
def split_padded(a,n):
    padding = (-len(a))%n
    return np.split(np.concatenate((a,np.zeros(padding))),n)

1 commentaires

Qu'est-ce que c'est dans cette réponse?



33
votes

Vous recherchez NP.Array_split? Voici la docstring:

Split an array into multiple sub-arrays.

Please refer to the ``split`` documentation.  The only difference
between these functions is that ``array_split`` allows
`indices_or_sections` to be an integer that does *not* equally 
divide the axis.

See Also
--------
split : Split array into multiple sub-arrays of equal size.

Examples
--------
>>> x = np.arange(8.0)
>>> np.array_split(x, 3)
    [array([ 0.,  1.,  2.]), array([ 3.,  4.,  5.]), array([ 6.,  7.])]


0 commentaires

0
votes

Vous pouvez diviser des tableaux en morceaux inégaux en passant des indices en tant que liste Exemple XXX


0 commentaires