I have a very long dataframe with many columns of the form k1, p1, k2, p2,...,kn, pn such as
k1 p1 k2 p2 k3 p3 ...
-0.001870 0.000659 -0.005000 0.000795 -0.003889 0.000795 ...
-0.002778 0.000556 0.000795 0.001667 0.000795 0.002778 ...
How could I build, in the most pythonic way, a numpy array with the k’s and p’s separated into arrays, like [[[-0.001870,-0.005000,-0.003889,...],[0.000659,0.000795,0.000795...]],[[-0.002778, 0.000795, 0.000795...],[0.000556, 0.001667, 0.002778...]], ...[[...],[...]]]
>Solution :
out = df.to_numpy().reshape((len(df), 2, -1), order='F')
Output:
array([[[-0.00187 , -0.005 , -0.003889],
[ 0.000659, 0.000795, 0.000795]],
[[-0.002778, 0.000795, 0.000795],
[ 0.000556, 0.001667, 0.002778]]])