"numpy.interp" ValueError: object too deep for desired array
"numpy.interp" ValueError: object too deep for desired array
我有一个数据集,其中包含一组 x 值和多组具有相同 x 值集的 y 值。例如,
X Y2 Y3
0 2 1
2 4 15
4 7 20
6 4 30
8 5 10
10 0.2 1
12 0.7 2
14 1 1
16 1.2 10
18 2.4 11
20 2.5 5
22 3 6
24 1 7
26 8 7
28 9 5
30 1 1.2
32 1.2 1.5
34 1.5 2
我想通过插值获得“new_x
”的 Y2 和 Y3 值。
new_x=np.arange(0,34,0.424)
.
array([ 0. , 0.424, 0.848, 1.272, 1.696, 2.12 , 2.544, 2.968,
3.392, 3.816, 4.24 , 4.664, 5.088, 5.512, 5.936, 6.36 ,
6.784, 7.208, 7.632, 8.056, 8.48 , 8.904, 9.328, 9.752,
10.176, 10.6 , 11.024, 11.448, 11.872, 12.296, 12.72 , 13.144,
13.568, 13.992, 14.416, 14.84 , 15.264, 15.688, 16.112, 16.536,
16.96 , 17.384, 17.808, 18.232, 18.656, 19.08 , 19.504, 19.928,
20.352, 20.776, 21.2 , 21.624, 22.048, 22.472, 22.896, 23.32 ,
23.744, 24.168, 24.592, 25.016, 25.44 , 25.864, 26.288, 26.712,
27.136, 27.56 , 27.984, 28.408, 28.832, 29.256, 29.68 , 30.104,
30.528, 30.952, 31.376, 31.8 , 32.224, 32.648, 33.072, 33.496,
33.92 ])
当我运行intrp_CC=np.interp(new_x,old_x,current_Y)
时,我得到ValueError: object too deep for desired array
。
知道为什么会发生这种情况以及我该如何解决它吗?
你读过文档了吗?
Returns the one-dimensional piecewise linear interpolant to a function
with given discrete data points (xp
, fp
), evaluated at x
.
fp : 1-D sequence of float or complex
1d fp
:
In [397]: np.interp(np.arange(10), np.arange(10), np.arange(20).reshape(2,10)[0,:])
Out[397]: array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.])
2d,多行,fp
- 你的错误:
In [398]: np.interp(np.arange(10), np.arange(10), np.arange(20).reshape(2,10))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-398-e1383ba2f0f0> in <module>()
----> 1 np.interp(np.arange(10), np.arange(10), np.arange(20).reshape(2,10))
/usr/local/lib/python3.6/dist-packages/numpy/lib/function_base.py in interp(x, xp, fp, left, right, period)
1306 fp = np.concatenate((fp[-1:], fp, fp[0:1]))
1307
-> 1308 return interp_func(x, xp, fp, left, right)
1309
1310
ValueError: object too deep for desired array
我认为询问显式 for 循环是否可以任何方式避免仍然是一个公平的问题.....该问题的答案是肯定的,前提是使用 scipy interpolate.interp1d模块而不是 numpy。
我有一个数据集,其中包含一组 x 值和多组具有相同 x 值集的 y 值。例如,
X Y2 Y3
0 2 1
2 4 15
4 7 20
6 4 30
8 5 10
10 0.2 1
12 0.7 2
14 1 1
16 1.2 10
18 2.4 11
20 2.5 5
22 3 6
24 1 7
26 8 7
28 9 5
30 1 1.2
32 1.2 1.5
34 1.5 2
我想通过插值获得“new_x
”的 Y2 和 Y3 值。
new_x=np.arange(0,34,0.424)
.
array([ 0. , 0.424, 0.848, 1.272, 1.696, 2.12 , 2.544, 2.968,
3.392, 3.816, 4.24 , 4.664, 5.088, 5.512, 5.936, 6.36 ,
6.784, 7.208, 7.632, 8.056, 8.48 , 8.904, 9.328, 9.752,
10.176, 10.6 , 11.024, 11.448, 11.872, 12.296, 12.72 , 13.144,
13.568, 13.992, 14.416, 14.84 , 15.264, 15.688, 16.112, 16.536,
16.96 , 17.384, 17.808, 18.232, 18.656, 19.08 , 19.504, 19.928,
20.352, 20.776, 21.2 , 21.624, 22.048, 22.472, 22.896, 23.32 ,
23.744, 24.168, 24.592, 25.016, 25.44 , 25.864, 26.288, 26.712,
27.136, 27.56 , 27.984, 28.408, 28.832, 29.256, 29.68 , 30.104,
30.528, 30.952, 31.376, 31.8 , 32.224, 32.648, 33.072, 33.496,
33.92 ])
当我运行intrp_CC=np.interp(new_x,old_x,current_Y)
时,我得到ValueError: object too deep for desired array
。
知道为什么会发生这种情况以及我该如何解决它吗?
你读过文档了吗?
Returns the one-dimensional piecewise linear interpolant to a function with given discrete data points (
xp
,fp
), evaluated atx
.fp : 1-D sequence of float or complex
1d fp
:
In [397]: np.interp(np.arange(10), np.arange(10), np.arange(20).reshape(2,10)[0,:])
Out[397]: array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.])
2d,多行,fp
- 你的错误:
In [398]: np.interp(np.arange(10), np.arange(10), np.arange(20).reshape(2,10))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-398-e1383ba2f0f0> in <module>()
----> 1 np.interp(np.arange(10), np.arange(10), np.arange(20).reshape(2,10))
/usr/local/lib/python3.6/dist-packages/numpy/lib/function_base.py in interp(x, xp, fp, left, right, period)
1306 fp = np.concatenate((fp[-1:], fp, fp[0:1]))
1307
-> 1308 return interp_func(x, xp, fp, left, right)
1309
1310
ValueError: object too deep for desired array
我认为询问显式 for 循环是否可以任何方式避免仍然是一个公平的问题.....该问题的答案是肯定的,前提是使用 scipy interpolate.interp1d模块而不是 numpy。