I want to create a numpy array variables with a certain structure, as in the example below, consisting of the variables X and Y for a meshgrid and additional parameters params. I need this in the context of plotting a 3D surface plot for a function f(variables).
This is how the variables array should look like with some arbitrary params 5, 5, 5.
import numpy as np
X = np.linspace(0, 2, num=3)
Y = np.linspace(0, 2, num=3)
X, Y = np.meshgrid(X, Y)
variables = np.array([X, Y, 5, 5, 5])
print(variables)
With the desired output:
array([[[ 0., 1., 2.],
[ 0., 1., 2.],
[ 0., 1., 2.]],
[[ 0., 0., 0.],
[ 1., 1., 1.],
[ 2., 2., 2.]],
5, 5, 5])
And my questions is how can I construct this when having the parameters 5, 5, 5 in a numpy array also. (And explicitly not having something like [X, Y, [5, 5, 5]].)
params = np.array([5, 5, 5])
I already looked at different numpy functions like stack or concatenate, but could not figure it out. I'm rather new to numpy, so thanks for any help.
np.array([X, Y, 5, 5, 5])isn't your expected o/p, can you list out the same for that sample?variables = np.array([X, Y, params])which would yield the structure stated abovevariables = np.array([X, Y, 5, 5, 5]). Did I explain myself?print(result)ought to look like for a small example.