简体   繁体   English

Python Numpy Linspace function 用于二维数组

[英]Python Numpy Linspace function for bidimensional array

I know it is possible to create numpy arrays using the Linspace function.我知道可以使用 Linspace function 创建 numpy arrays。 For example, given a range [x,y] I can make a vector of z elements equally distanced in [x,y]例如,给定一个范围 [x,y] 我可以在 [x,y] 中创建一个等距的 z 元素向量

v = np.linspace(x, y, z, retstep=True) v = np.linspace(x, y, z, retstep=True)

What if one needs more dimensions?如果需要更多维度怎么办? Is it possible to use the same function to generate a 3x4 array?是否可以使用相同的 function 生成 3x4 数组? I tried by creating simple arrays and then merge them, but I don't think that is an efficient way to do that我尝试创建简单的 arrays 然后合并它们,但我认为这不是一种有效的方法

You can use arrays for start and stop point of linspace:您可以使用 arrays 作为 linspace 的起点和终点:

x=np.linspace((0,0,0), (3,5,14), 4, axis=1)
print(x)

This will give the output:这将给出 output:

[[ 0.          1.          2.          3.        ]
 [ 0.          1.66666667  3.33333333  5.        ]
 [ 0.          4.66666667  9.33333333 14.        ]]

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

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