我尝试通过克里格法在二维网格上插值响应,如下示例: How to interpolate 2D spatial data with kriging in Python?
但是,当我试图在OpenTURNS中从1D数组创建样本时
import numpy as np
import openturns as ot
observations = ot.Sample(np.array([1,2,3]))
我一直在犯这个错误
TypeError: Wrong number or type of arguments for overloaded function 'new_Sample'.
Possible C/C++ prototypes are:
OT::Sample::Sample()
OT::Sample::Sample(OT::UnsignedInteger const,OT::UnsignedInteger const)
OT::Sample::Sample(OT::UnsignedInteger const,OT::Point const &)
OT::Sample::Sample(OT::Sample const &,OT::UnsignedInteger const,OT::UnsignedInteger const)
OT::Sample::Sample(OT::SampleImplementation const &)
OT::Sample::Sample(OT::Sample const &)
OT::Sample::Sample(PyObject *)
这也不起作用:
observations = ot.Sample(np.array([[1],[2],[3]]))
例外情况是因为这是一种模棱两可的情况。
array
包含3个值:Sample
类不知道此数据是对应于维度1中由3个点组成的样本,还是对应于维度3中有一个点的样本阐明这一点的类别有:
Python数据类型和OpenTURNS数据类型之间有自动转换:
list
或tuple
或1D numpyarray
会自动转换为ot.Point()
list
列表或2D numpyarray
会自动转换为ot.Sample()
创建一维
Sample
的常用方法是从浮点数列表中创建。 请让我举例说明这三种结构(案例1)要从1D数组创建点,只需将其传递给
Point
类:这将打印
[1,2,3]
,即维度3中的一个点(案例2)为了从2D数组创建
Sample
,我们添加了所需的方括号这张照片是:
这是一个由3个点组成的样本;每个点都有一个维度
(案例3)我们经常需要从浮动列表中创建一个
Sample
。这可以通过列表理解更容易地完成这将打印与上一示例中相同的样本。 最后一个脚本:
在我的机器上很好用。请注意,OpenTURNS只管理浮点值的点,而不管理
int
类型的点。这就是为什么我写:让这一切变得足够清楚。 但是,对
array
函数的调用是不必要的。使用起来更简单:相关问题 更多 >
编程相关推荐