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]
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]
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)
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:]