2

我想创建一个包含函数的数组f(x,y,z)。如果它是一个变量的函数,我会这样做,例如:

sinx = numpy.sin(numpy.linspace(-5,5,100))

进入sin(x)_ x_[-5,5]

例如,我怎样才能做到这一点sin(x+y+z)

4

3 回答 3

5

我似乎找到了一种方法:

# define the range of x,y,z
x_range = numpy.linspace(x_min,x_max,x_num)
y_range = numpy.linspace(y_min,y_max,y_num)
z_range = numpy.linspace(z_min,z_max,z_num)

# create arrays x,y,z in the correct dimensions
# so that they create the grid
x,y,z = numpy.ix_(x_range,y_range,z_range)

# calculate the function of x, y and z
sinxyz = numpy.sin(x+y+z)
于 2009-09-05T12:00:49.777 回答
4
xyz = numpy.mgrid[-5:5,-5:5,-5:5]
sinxyz = numpy.sin(xyz[0]+xyz[1]+xyz[2])
于 2010-02-18T11:20:02.593 回答
-1

numpy.mgrid 函数同样可以正常工作:

x,y,z = numpy.mgrid[x_min:x_max:x_num, y_min:y_max:y_num, z_min:z_max:z_num]  
sinxyz = numpy.sin(x+y+z)

编辑:让它工作x_numy_num并且z_num必须是明确的数字,后跟j,例如,x,y = numpy.mgrid[-1:1:10j, -1:1:10j]

于 2013-04-03T01:16:44.490 回答