比较C中的double值(comparing double values in C)
我有两个双数组,我们说A和B.我想比较他们的结果到7个有效数字。 以下是比较正确的吗?
k = pow(10,7); for(...) { if(((int)A[i]*k)!=((int)B[i]*k)) { ... } }
i have two double arrays, let's say A and B. i want to compare their results to 7 significant digits. will the following be correct to make the comparison?
k = pow(10,7); for(...) { if(((int)A[i]*k)!=((int)B[i]*k)) { ... } }
原文:https://stackoverflow.com/questions/11747251
最满意答案
您收到的错误消息:
TypeError: Only length-1 arrays can be converted to Python Scalars
字面意思是:你已经在一个单一的值或单个元素的数组所期望的地方提供了一个多于一个元素 的数组 。
所以传递给
model.train(samples, responses)
的参数之一需要和标量......但是哪个?查看KNearest类的最新文档,让我们看到StatsModel.train方法的签名:
虚拟布尔cv :: ml :: StatModel :: train(InputArray样本,int布局,InputArray响应)
显然,新增了一个
layout
参数。 但它的含义有点模糊从文档。不知道你的文件内容,我不知道你是否需要传递
ROW_SAMPLE
或COL_SAMPLE
,但用这些信息武装,我可以找到一个类似的问题 ,其解决方案是添加cv2.ml.ROW_SAMPLE
作为第二个参数列车方法:model.train(samples, cv2.ml.ROW_SAMPLE, responses)
The error message that you are getting:
TypeError: Only length-1 arrays can be converted to Python Scalars
literally means: you have provided an array of more than one element in a place where a single value or an array of a single element was expected.
So one of the arguments passed to call
model.train(samples, responses)
requires and scalar... but which?A look at the latest documentation of KNearest class, allow us to see the signature of the StatsModel.train method:
virtual bool cv::ml::StatModel::train ( InputArray samples, int layout, InputArray responses )
Apparently, a new
layout
argument was added. But it's meaning is a little obscure from the documentation.Without knowledge of the contents of you file, I can't tell if you need to pass
ROW_SAMPLE
orCOL_SAMPLE
, but armed with that information, I could find a similar question, whose solution was to addcv2.ml.ROW_SAMPLE
as second argument to the train method:model.train(samples, cv2.ml.ROW_SAMPLE, responses)
相关问答
更多-
查看np.prod()的文档 : numpy.prod(a, axis=None, dtype=None, out=None, keepdims=
) 返回给定轴上的数组元素的乘积。 np.prod()函数不适用于两个不同的数组。 对于点积,您可以使用np.dot()函数或等效的ndarray.dot()方法 : >>> A = np.array([1, 2, 3, 4, 5]) >>> np.dot(A, A) 55 >>> A.dot(A) ... -
查看concatenate文档 连接((a1,a2,...),axis = 0) 该函数需要2个参数。 首先是一个列表或元组,您想要加入的数组。 第二个是一个数字,表示该轴。 并且它返回一个新的数组。 它不适用。 X_train = df_train.as_matrix() 所以这是2d(8899,n),n大于9.根据pd文档,这是一个numpy array不是一个numpy matrix (这很重要) temp_train_long=(X_train[:,3] - X_train[:,7])**2#lo ...
-
只有length-1数组可以转换为Python标量[关闭](only length-1 arrays can be converted to Python scalars [closed])[2022-04-22]
abs(x)是一个数组,你不能将数组转换为浮点值,即错误。 您可以编写for循环来进行计算,但numpy可以通过numpy.where进行矢量化。 有关更多信息,请阅读文档 : import numpy as np x = np.arange(-20, 20, 0.01) x0 = 5 U0 = 200 u = np.where(np.abs(x) >= x0, U0, U0*np.abs(x)/x0) plot(x, u, lw=3) 输出: 你也可以使用分段函数,它可以处理更复杂的情况。 abs(x) ... -
错误在np.complex(0,a)。 它并不指望'a'是一个数组。 与之比较: c = np.exp(np.complex(0,a[0])). 由于a已经是一个复数的数组,所以你不能直接计算它吗? (尽管给定指数的大小,这会导致inf + 0.j) c = np.exp(a) The error is in np.complex(0,a). It doesn't expect 'a' to be an array. Compare with: c = np.exp(np.complex(0,a[0] ...
-
类型错误:只能将长度为1的数组转换为Python标量(Type Error: Only length-1 arrays can be converted to Python Scalars)[2024-03-19]
您收到的错误消息: TypeError: Only length-1 arrays can be converted to Python Scalars 字面意思是:你已经在一个单一的值或单个元素的数组所期望的地方提供了一个多于一个元素 的数组 。 所以传递给model.train(samples, responses)的参数之一需要和标量......但是哪个? 查看KNearest类的最新文档,让我们看到StatsModel.train方法的签名: 虚拟布尔cv :: ml :: StatModel : ... -
那是你要的吗? In [191]: df.groupby('label').agg({'importe':'sum'}) Out[191]: importe label 0 500.7 1 700.9 2 300.6 要么: In [192]: df.groupby('label')['importe'].sum() Out[192]: label 0 500.7 1 700.9 2 300.6 Name: importe, dty ...
-
我想知道你的数据是否显示出指数衰减的速度。 数学模型可能不是最合适的模型。 请参阅curve_fit的doc字符串 f:callable模型函数f(x,...)。 它必须将自变量作为第一个参数,并将参数作为单独的剩余参数。 因为你的公式基本上是: k=A*ma.exp(-E/(R*T)) , func中参数的正确顺序应该是(T, A, E)或(T, E, A) 。 关于A和E的顺序,它们并不重要。 如果你翻转它们,结果也会被翻转: >>> def func(T, A, E): return A*ma ...
-
你在theta_dependence(1, 1.52, thetain, thetaout)中传递thetaout来计算R但是thetaout是一个空列表,如下所示: thetaout = array(stuff, float) 。 这就是电子邮件的原因。 虽然您在find_thetaout函数中计算了该thetaout ,但它是一个局部变量,并且不会修改全局thetaout 。 所以,这是我的建议: 在find_thetaout函数中插入global thetaout语句: def find_thetao ...
-
删除所有这些float调用,你的代码应该工作(作为浮点数 )。 您试图将numpy数组强制转换为单个浮点值,但这些值不起作用。 Drop all of those float calls and your code should work (as floats). You're trying to coerce numpy arrays into single float values which isn't going to work.
-
重现这样的错误: In [32]: a Out[32]: array([0, 1, 2]) In [33]: range(a) --------------------------------------------------------------------------- TypeError Traceback (most recent call last)
in 相关文章
更多- java double 保留两位小数
- Guava Doubles类-double基本类型的实用工具类
- INSERT INTO blog_appitem (user_id,appid,app_secret,is_valid) VALUES (1, 'wxf415741de036114c','48e1e345fd5f11c93af18ff1714c7f78',1)
- C中传值与传址的困惑
- C语言面试题(带答案)一
- JSTL详解之c:forEach
- Hadoop 上使用C 语言编程
- 《C/C++图像处理编程》扫描版[PDF]
- C程序访问Hadoop
- 《从零开始学Visual C++》扫描版[PDF]
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)