I have a numpy array: np.array([0, 93, 94, 96, 228])
, which I need to split into multiple lists like:
[0,93]
[93,94]
[94,96]
[96,228]
How can I solve this in python?
I have a numpy array: np.array([0, 93, 94, 96, 228])
, which I need to split into multiple lists like:
[0,93]
[93,94]
[94,96]
[96,228]
How can I solve this in python?
Something like this will do:
Firstly import numpy
,
import numpy as np
Next, assign a variable to your numpy
array,
a = np.array([ 0, 93, 94, 96, 228])
Create an empty list to store the desired output,
b=[]
Append elements and creating new lists,
for i in range(0, len(a)-1):
b.append([a[i], a[i+1]])
And then the print the output
for each in b:
print(each)
Doing so, gives the desired output.