I have data in an nxm
2D table like this:
In my Python code, it looks like this:
import numpy as np
xData = np.array([-225, -200, -175])
yData = np.array([0.1, 1.0, 5.0])
zData = np.array([[749.36, 698.96, 471.88],
[1012.1, 987.87, 890.69],
[1283.9, 1270.1, 1217.1]])
In order to do some curve fitting, I would like to have it in the form of three 1D arrays where each has the size 1 x (nxm)
:
xData = np.array([-225, -225, -225, -200, -200, -200, -175, -175, -175])
yData = np.array([0.1, 1.0, 5.0, 0.1, 1.0, 5.0, 0.1, 1.0, 5.0])
zData = np.array([749.36, 698.96, 471.88, 1012.1, 987.87, 890.69, 1283.9, 1270.1, 1217.1])
What is a nice and clean way to achieve this? Note that in general, xData
and yData
are not evenly spaced.
This should do the trick:
xData = np.repeat(xData, np.shape(zData)[1])
yData = np.tile(yData, np.shape(zData)[0])
zData = np.reshape(zData, (1, np.size(zData)))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.