- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 1000 x 1000 网格中使用 scipy.interpolate.griddata 进行插值。当我有一个包含 1,000 个 (x,y,z) 值的点云时,计算只需要几秒钟。但现在我有 1,000,000 个值。所以我创建了一个循环来从这 1,000,000 个值中提取 1,000 个值,如下所示:
p = [...]
z = [...]
#p and z are my lists with 1,000,000 values
p_new = []
z_new = []
for i in range(1000000):
if condition:
#condition is True for about 1000 times
p_new.append(p[i])
z_new.append(z[i])
print 'loop finished'
points = np.array(p_new)
values = np.array(z_new)
grid_z1 = griddata(points, values, (grid_x, grid_y), method='cubic')
plt.imshow(grid_z1.T, origin='lower')
plt.show()
print len(p_new)
返回 1000
,因此我的循环按预期工作。但是在我的循环结束后,我在等待 15 分钟后取消了我的程序,因为什么也没发生。
所以最后我的问题是:尽管在这两种情况下(默认情况下有 1000 个值和从 1000000 中提取它们的 1000 个值)我有相同数量的值,但为什么这个计算要花这么长时间?在我的输出中 loop finished
我可以看到循环只需要大约 10 秒,所以它应该与我的循环无关 =/
最佳答案
我看不出这里有什么不寻常的事情发生——据我所知所花费的时间插值大致与点中元素的数量成正比云。
这是一些测试数据:
def fake_data(n):
# xy coordinates for an n-by-n grid
grid = np.indices((n,n),dtype=np.float32).reshape(2,-1).T
# interpolated coordinates
xy_i = grid.copy()
# not monotonically increasing
np.random.shuffle(xy_i)
# values
z = np.random.rand(n**2)
# input coordinates
xy = grid.copy()
# not regularly gridded
xy += np.random.rand(*xy_i.shape)*0.25
# pick n random points to use
inc = np.random.choice(np.arange(n**2),(n,),replace=False)
xy = grid[inc,:]
z = z[inc]
return xy, z, xy_i
对于所有三种方法,N 与时间的对数-对数图大致是一条直线,斜率为 ~2,即它们都需要 O(N^2) 时间。
如果在您的情况下,您发现线条不是直线而是向上偏离对于较大的 N 值,这可能表明您遇到了一些其他问题,例如内存不足和交换区。
关于python插值需要很长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19122893/
这个问题在这里已经有了答案: Isn't an Int64 equal to a long in C#? (2 个答案) 关闭 9 年前。 它不应该是一个整数类型吗? 这样,一些使用 int 的函数
当我遇到一些我想知道的事情时,我正忙着解析一个二进制文件。 Stream.Position属性的类型为Int64或long。为什么是这样?因为流中的位置不能为负,所以使用 UInt64 不是更有意义吗
所以第一部分是我从用户那里获得输入,在本例中,输入是“1”作为从另一个函数接收的字符值。 printf ("\nPlease enter 1, 2, 3 or q: "); option =
我正在尝试使用以下代码从 REST 服务返回 JSON: $categories = $categoriesController->listAll(); if($categories){ hea
我阅读了文档,它说 long 是 %li,但打印输出返回为 -2147024891。是什么赋予了? 最佳答案 您甚至没有提供要打印的号码,但我猜您已经无意中发现了签名打印和未签名打印之间的区别。 使用
我正在创建自定义购物车,我正在构建一个查询,该查询从检索我刚刚保存到购物车表中的 session_id 开始。我知道这个值被保存了,我在 mysql 命令行运行这个查询,它返回我需要的但我没有将值放入
我有一个包含 textView 的 scrollView。如果文本很长并且不适合屏幕,我想增加 textView 高度(我想我可以通过添加 NSLayoutConstraint outlet 并修改它
我有一个基本的数据库处理程序类,其中有一个使用 PDO::FETCH_ASSOC 参数返回结果集的公共(public)方法: public function resultSet() { $th
在后台线程中,我调用 PublishSubject.onNext(); 并在主线程中通过 subscribe(PublishSubject.filter(message -> message.getI
我想知道为什么 Amazon Web Services 控制台登录页面有这么长的 url?为什么不只发布数据而不显示其中包含大量数据的冗长 url。以这种方式实现有什么充分的理由吗? 最佳答案 我认为
这个问题在这里已经有了答案: Can I mix MySQL APIs in PHP? (4 个答案) 关闭 6 年前。 希望我犯了一个快速而明显的错误,我浏览了 previous question
我得到了答案:如果我禁用了cookie,那么使用URL重定向我可以传递JSESSIONID,但我的URL已经很长,因为我使用它有约束的GET方法。那怎么办我应该使用我的 session 吗?我希望我的
目前,当我使用 DOMDocument 对象并调用 saveHTML() 时,它会自动添加一些我不需要的 html 标签。我尝试了此处建议的解决方案 ( https://stackoverflow.c
我是一名优秀的程序员,十分优秀!