[英]Numpy : ValueError: object of too small depth for desired array
I am trying to convert a MATLAB code to Python where I am stuck of how to import this line to Python: 我正在尝试将MATLAB代码转换为Python,在这里我被困在如何将此行导入Python中:
YDFA_xa_p = interp1(data(:,1),data(:,2),YDFA_lam_p*1e9,'linear')*1e-24;
Now for Python I have changed it as: 现在对于Python,我将其更改为:
YDFA_xa_p = numpy.interp(data[:, 1], data[:, 2], YDFA_lam_p * 1e9) * 1e-24
data[:,1] and data[:,2] and YDFA_lam_p values are:
[ 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.] [ 3. 3. 3. 3. 3. 3. 3. 3. 3. 3.] 915.0
The issue I see is that the variable YDFA_lam_p is a float variable while it is expecting an array of float of 10 elements? 我看到的问题是,变量YDFA_lam_p是一个float变量,而它期望由10个元素组成的float数组?
If I am correct in my understanding how can I correct it ? 如果我理解正确,该如何纠正? I tried ways I find in google but it just isn't working. 我尝试了我在Google中找到的方法,但是它不起作用。
When I use the same sort of numbers in Octave I get a similar error: 当我在Octave中使用相同类型的数字时,会出现类似的错误:
octave:32> interp1([2,2,2,2],[3,3,3,3],900)
warning: interp1: multiple discontinuities at the same X value
error: mkpp: at least one interval is needed
You've given it one point (repeatedly) and are asking it to interpolate some value way off in left field. 您已经给了它一分(重复),并要求它在左侧字段中插值一些值。
A correct sample use is: 正确的示例用法是:
octave:32> interp1([1,2,3,4,5],[3,3.5,2,2.5,1],2.33,'linear')
ans = 3.0050
the equivalent Python (note different order of variables): 等效的Python(请注意变量的不同顺序):
In [364]: np.interp(2.33,[1,2,3,4,5],[3,3.5,2,2.5,1])
Out[364]: 3.005
Read help(np.interp)
to see more about its inputs. 阅读help(np.interp)
以了解有关其输入的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.