0
我正在尝试为数值算法编写一个函数。函数应该考虑一些状态变量的维数和上下界。然后,我希望函数在维度上创建一个状态空间。我可以使用griddata和静态定义维度的数量来轻松地编写它,但我想动态地定义空间。有人可以告诉我如何动态创建阵列传递给meshgrid吗?或者说明如何将字典解压缩到数组中?(因为这似乎是建议的方法)?甚至如何通过meshgrid数组列表?在循环中创建变量以动态创建griddata()
下面是我在做什么静态版本:
import numpy as np
#Define the bounds of the state space
up_bound = 1
low_bound = 0
#Define the number of dimensions
dim = 4
m = 2^j - 1, where j is the identifier of the grid.
j = 6
#Define number of points
m = 2**j - 1
#Define the state space axes using the linear space function
Xi = np.linspace(low_bound, up_bound, m)
Phi = np.linspace(low_bound, up_bound, m)
omega = np.linspace(low_bound, up_bound, m)
delta = np.linspace(low_bound, up_bound, m)
space = np.asarray(np.meshgrid(Xi, Phi, omega, delta))
完美!感谢您的快速响应。现在真正的问题:你有什么想法如何加快meshgrid?我尝试过使用cython,但它并没有给我更多的速度。 – pdevar 2014-09-27 16:19:35
谢谢unutbu!真正有用的编辑。 – pdevar 2014-09-30 06:50:16