-3

I have an array S = [1, 10, 14, 25, 62, 85, 20, 95]. I need to devide S to two sector using numpy.

Expected output is:

S1 = [1, 10, 14, 25]
S2 = [62, 85, 20, 95]
shamal
  • 24
  • 6
  • 1
    Does this answer your question? [How do you split a list into evenly sized chunks?](https://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks) – accdias Mar 20 '21 at 12:15

2 Answers2

0

You can split the array easily:

import numpy as np
S = np.array([1, 3, 5, 10, 2, 4, 9, 5, -1])
S1 = np.array_split(S, 2)
print(S1)

also without external library

S = [1, 3, 5, 10, 2, 4, 9, 5, -1]
S1 = S[:4]
S2 = S[4:9]
print(S1)
print(S2)
Dilux
  • 136
  • 7
0

If you want to split the array into two halves, you can do it in this way:

S = [1, 10, 14, 25, 62, 85, 20, 95]
S1 = S[:len(S)//2]
S2 = S[len(S)//2:]
SAI SANTOSH CHIRAG
  • 2,046
  • 1
  • 10
  • 26