简体   繁体   English

numpy - 多维度的meshgrid

[英]numpy - meshgrid for multiple dimensions

numpy has a beautiful function which generate multidimensional grid. numpy具有生成多维网格的漂亮功能。 It is easy to work with it when number of dimension is low and is known in advance, but what to do when number of dimension is only known at time of execution or simply big and it takes too long to type. 当尺寸数量低并且事先已知时,容易使用它,但是当尺寸的数量仅在执行时知道或者仅仅大而且需要太长时间进行打字时该怎么办。 I guess I am looking for something like 我想我正在寻找类似的东西

 import numpy as np

 x = np.meshgrid(y)

where y is an array of arrays of evaluation points, for example 例如,y是评估点数组的数组

y = [array([-3.,  0.,  3.]) array([-3.,  0.,  3.]) array([-3.,  0.,  3.])]

Suggestions? 建议?

Use the * -operator (ie the unpacking operator): 使用* -operator(即解包运算符):

x = np.meshgrid(*y)

See https://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists 请参阅https://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM