简体   繁体   English

numpy:ValueError:对象深度太小,无法获得所需的数组

[英]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.

相关问题 插值问题 - ValueError:所需数组的深度太小(Python,numpy) - Interpolation Issue - ValueError: object of too small depth for desired array (Python, numpy) np.interp 在脚本中失败 - 但在独立测试中没有? (ValueError:object 所需数组的深度太小) - np.interp fails in script - but not in standalone test? (ValueError: object of too small depth for desired array) scipy.signal.lfilter: *** ValueError: 所需数组的深度太小 - scipy.signal.lfilter: *** ValueError: object of too small depth for desired array 值错误:对象深度不足,无法容纳所需数组 - Value Error: object of too small depth for desired array 使用 scipy.signal.lfilter 时,实现巴特沃斯带通滤波器遇到:“ValueError: object of too small depth for desired array”错误 - Implementing Butterworth bandpass filter running into: "ValueError: object of too small depth for desired array" error when using scipy.signal.lfilter ValueError:对象对于所需数组而言太深 - ValueError: object too deep for desired array ValueError:对象太深,无法放入所需的数组(netcdf) - ValueError: object too deep for desired array (netcdf) ValueError:'对象太深,不适合所需的数组' - ValueError: 'object too deep for desired array' Matlab 过滤器与深度太小的 Python lfilter ValueError 对象 - Matlab filter with Python lfilter ValueError object of too small depth ValueError:使用卷积时对象对于所需数组来说太深了 - ValueError: object too deep for desired array while using convolution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM